• 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

abstract strictfp class legal?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't it odd that when declaring a method, you can't mix "abstract" with "strictfp", like

abstract strictfp void aMethod(); //won't compile

but you can declare an abstract class which is also strictfp ???, like

public abstract strictfp class aClass { ... } //will compile fine

I understand why the first code won't compile, but not why the second one does compile.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you declare a method as strictfp you're saying "This method uses the IEEE754 standard for floating point operations" and hence you can't have a method that's abstract and strictfp as an abstract method isn't doing jack, let along implementing the IEEE 754 standard.
"Abstract methods cannot be marked synchronized, strictfp or native, all of which are modifiers describing something about the implementation of a method" - From the KB book.
"Marking a class as strictfp means that any method code in the class will conform to the IEEE754 standard rules for floating points. Without that
modifier, floating points used in the methods might behave in a platform-dependent way. If you don�t declare a class as strictfp, you can still get strictfp behavior on a method-by-method basis, by declaring a method as strictfp."
Sashi
 
John Brown
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sashi for your response. Yes, I already knew that when I posted the thread.
Let me put it another way: declaring a class as strictfp is like declaring all its methods as strictfp; i.e.:



is the equivalent of



So, I assumed that



is the equivalent of



But you can't have "abstract strictfp" methods. Then it hit me, an abstract class may have concrete (nonabstract) methods too; so, when declaring an abstract class as strictfp, the compiler makes an exception, and applies the "strictfp" modifier only to concrete methods. Right?
 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if an abstract class has non abstract methods, it is legal to declare the class as abstract and strictfp.


The above is legal and the compiler is happy to accept it.
HTH,
Sashi
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic