2012-04-06 49 views
0
if(System.currentTimeMillis() > _thrust_lag + _thrust_delay); 
    { 
     this._thrust3Position = new_Position; 

     Log.w("Thrust Lag + Delay", Long.toString(_thrust_lag + _thrust_delay)); 
     Log.w("Current Time", Long.toString(System.currentTimeMillis())); 

     _thrust_lag = System.currentTimeMillis(); 
    } 

輸出是: 推力滯後+延時:1333710037096 CURRENTTIME:1333710027174當前時間IF語句GT ThrustLag

_thrust_delay = 10000 BTW。

這應該返回false但它不是,它不斷輸出這個語句。任何任何想法?還是我錯過了一些基本的東西?

這個語句中的所有變量都是長整型的,_thrust_lag在構造函數和函數中只被設置一次,所以問題點在這裏。

回答

4

尾隨;結尾爲if聲明:將其刪除。在沒有語句分支

拖尾;分號結果被執行:

if (...); 

是相同:

if (...) 
{ 
} 

這意味着在張貼代碼{}內的語句是始終執行。

+0

OMG的東西很簡單,我看着這個30分鐘,並認爲WTF?非常感謝! – 2012-04-06 11:14:11

+0

+1很好抓。 – 2012-04-06 11:15:33