2016-01-24 30 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等等。基本上,它可以存储有小数的数字。 –