1

I know that the strictfp keyword can be applied on methods, classes and interfaces.

strictfp class A{} //Accept

strictfp interface M{} //Accept  

class B{  
strictfp A(){} // Not Accept
}  
user207421
  • 305,947
  • 44
  • 307
  • 483
Shakthi Vel
  • 61
  • 1
  • 6

3 Answers3

0

it can be used on methods as well. but not on constructors. and in your example you have applied it to a constructor not to a method.

But, Once applied to class it will be automatically applied to the static and instance blocks, all class variables, all constructors

sasankad
  • 3,543
  • 3
  • 24
  • 31
0

if you are applying strictfp to class it is applicable to all the members. as you can see in javadoc:

The effect of the strictfp modifier is to make all float or double expressions within the class declaration (including within variable initializers, instance initializers, static initializers, and constructors) be explicitly FP-strict

This implies that all methods declared in the class, and all nested types declared in the class, are implicitly strictfp

strictfp keyword usage

note : The strictfp keyword can not be applied explicitly on abstract methods, variables or constructors.

Community
  • 1
  • 1
Prashant
  • 2,556
  • 2
  • 20
  • 26
0

Classes

You can explicitly declare a class strictfp AND the methods within that class explicitly strictfp but NOT the member variables e.g.

// Compiles Fine
strictfp class A {strictfp void mA(){ } int i=0; } 

// Compiler Error because of declaring i variable strictfp 
strictfp class B {strictfp void mB(){ } strictfp int i=0;}

// Compiler Error because of declaring i variable strictfp 
class C {strictfp void mC(){ } strictfp int i=0; }

Interfaces

You cannot in declare an interface strictfp AND the methods/members within that interface explicitly strictfp as it will give a compiler error:

// Compiler Error
strictfp interface A {strictfp double mA(); static int i = 0;} 

Solution: Declare the interface strictfp and NOT the methods/members within the interface. By doing this all of the methods and members within the interface will be strictfp

//Compiles Fine
strictfp interface A {double mA(); static int i = 0;}