橘子味的心
标题:Java strictfp关键字

Java strictfp关键字确保您将在每个平台上获得相同的结果,如果在浮点变量中执行操作。 不同平台的精度可能不同,这就是为什么java编程语言提供了strictfp关键字,它用于在每个平台上获得相同的结果。 所以,现在我们就可以更好的控制浮点数据类型运算了。

strictfp关键字的全法代码

strictfp关键字可以应用于方法,类和接口。

  1. strictfp class A{}//strictfp applied on class
  2.  
  3. strictfp interface M{}//strictfp applied on interface
  4.  
  5. class B{
  6. strictfp void m(){}//strictfp applied on method
  7. }
  8. Java

strictfp关键字的非法代码

strictfp关键字不能应用于抽象方法,变量或构造函数。

  1. class B{
  2. strictfp abstract void m();//Illegal combination of modifiers
  3. }
  4.  
  5. class B1{
  6. strictfp int data=10;//modifier strictfp not allowed here
  7. }
  8.  
  9. class B2{
  10. strictfp B(){}//modifier strictfp not allowed here
  11. }
  12. Java