• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Non access modifier strictfp and intefaces

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The non-access modifier strictfp can be applied to abstract class. This makes sense because a abstract class can have non-abstract methods and when applied stricfp will be applied to all the non-abstract methods. So any floating point computation in those non-abstract methods will follow strictfp rules.
My question
a) Does strictfp gets applied to abstract methods in a abstract class?
b) Once when a concrete class extends this abstract class and implement the abstract methods, will strictfp be propograted to these methods?
c) We know that strictfp cannot be applied to a abstract method For ex
abstract strictfp void test(); is illegal. Then how come strictfp can be applied to an interfact? For example
strictfp abstract interface TestInter {} is legal. Yeah abstract keyword is optional here.
d) The question in b, Will this apply to the class implementing strictfp method.

Thanks
Deepak
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak,

Syntax-wise, the most important thing you need to understand regarding strictfp is this: the strictfp modifier applies only to the single immediate class or method implementation that it appears with. It is not part of a method's signature, and so it is not automatically propagated to an overriding method. A strictfp method can override a non-strictfp method, and vice versa. (Note that the same freedom applies to synchronized methods.) That's why it doesn't make sense to use the strictfp modifier (or, for that matter, synchronized) for abstract methods.

On to your questions:

a) Does strictfp gets applied to abstract methods in a abstract class?


No. strictfp is intended to modify the behavior of a single specific implementation, so it doesn't make sense to talk about a strictfp abstract method.

b) Once when a concrete class extends this abstract class and implement the abstract methods, will strictfp be propograted to these methods?


Nope.

c) We know that strictfp cannot be applied to a abstract method For ex
abstract strictfp void test(); is illegal. Then how come strictfp can be applied to an interfact? For example
strictfp abstract interface TestInter {} is legal. Yeah abstract keyword is optional here.


You may be surprised to learn this dark secret of Java: interfaces are allowed to contain nested classes. Therefore, when you apply the strictfp modifier to an interface, this means that you want all of its nested classes to be strictfp.

However, there is rarely--if ever at all--a good reason to design an interface containing a nested class, especially now that Java has enums. So please try to somehow forget that you ever knew about this language 'feature'.

d) The question in b, Will this apply to the class implementing strictfp method.


Nope. An overriding method (or its class) must explicitly specify that it is strictfp, even if the method it overrides is strictfp.
[ November 23, 2007: Message edited by: Kelvin Lim ]
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kelvin,
I had surprised myself yesterday when i was trying combination of interface and classes. I knew that interface could be nested inside a class but i was surprised to see the other way was also true.
Infact i wanted to ask why would anybody want to nest a class inside a interface but then there was a power failure here and i got disconnected from the world
Thanks
Deepak
reply
    Bookmark Topic Watch Topic
  • New Topic