2016-01-24 31 views
2

有人解釋關鍵字strictfp在下面的類中意味着什麼?關鍵字strictfp是什麼意思?

public strictfp class Demo { 
     public static void main(String[] args) { 
       double d = 8e+307; 
       /** affiche 4 * d /2 donc 2 * d */ 
       System.out.println(4 * d/2); 
       /** affiche 2 * d */ 
       System.out.println(2 * d); 
     } 
} 
+0

@Karthikeyan Vaithilingam我也發現這個[什麼是strictfp修飾符?什麼時候我會考慮使用它?](http://www.jguru.com/faq/view.jsp?EID=17544) – hulk

回答

4

Java的strictfp關鍵字確保您將獲得每個平臺上相同的結果,如果你在浮點variable.The strictfp關鍵字可以在方法,類和接口應用的操作。

strictfp class A{}//strictfp applied on class 
strictfp interface M{}//strictfp applied on interface 
class A{ 
strictfp void m(){}//strictfp applied on method 
} 

strictfp關鍵字不能應用於抽象方法,變量或構造函數。

class B{ 
strictfp abstract void m();//Illegal combination of modifiers 
} 
class B{ 
strictfp int data=10;//modifier strictfp not allowed here 
} 
class B{ 
strictfp B(){}//modifier strictfp not allowed here 
} 
+0

thnx但是浮點變量是什麼意思? – hulk

+1

@hulk,一個浮點變量是一個變量,它可以存儲數字爲2.6,8.430,0.086等等。基本上,它可以存儲有小數的數字。 –