To be clear, this question is strictly hypothetical. Personally, I have no Real World need for this behaviour; I discovered it accidentally.
Inspired by: How to make a (static) initializer block strictfp?
If I declare a Java class with strictfp
modifier:
public strictfp class PublicStrictfpClass
{
public double f() { return 2d / 3d; }
}
... then I test using Modifier.isStrict(int)
:
public static void main(String[] argArr)
{
if (! Modifier.isStrict(PublicStrictfpClass.class.getModifiers()))
{
throw new IllegalStateException("Unreachable code");
}
}
The above code fails: Method main()
throws IllegalStateException
. I tried a class declaration with and without method PublicStrictfpClass.f()
-- both fail.
Do I misunderstand ... ?
- The
strictfp
modifier when used in class declarations? - The method
Modifier.isStrict(int)
?
I am running this code from Linux using the latest patch for OpenJDK 8.
Finally, I did a bunch of Googling before asking this question. The keyword strictfp
is very rare in the wild!