Java strictfp關(guān)鍵字確保您將在每個(gè)平臺(tái)上獲得相同的結(jié)果,如果在浮點(diǎn)變量中執(zhí)行操作。 不同平臺(tái)的精度可能不同,這就是為什么java編程語言提供了strictfp關(guān)鍵字,它用于在每個(gè)平臺(tái)上獲得相同的結(jié)果。 所以,現(xiàn)在我們就可以更好的控制浮點(diǎn)數(shù)據(jù)類型運(yùn)算了。
strictfp關(guān)鍵字的全法代碼
strictfp關(guān)鍵字可以應(yīng)用于方法,類和接口。
strictfp class A{}//strictfp applied on class
strictfp interface M{}//strictfp applied on interface
class B{
strictfp void m(){}//strictfp applied on method
}
strictfp關(guān)鍵字的非法代碼
strictfp關(guān)鍵字不能應(yīng)用于抽象方法,變量或構(gòu)造函數(shù)。
class B{
strictfp abstract void m();//Illegal combination of modifiers
}
class B1{
strictfp int data=10;//modifier strictfp not allowed here
}
class B2{
strictfp B(){}//modifier strictfp not allowed here
}