• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

abstract and strictfp

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I have read in several places that although abstract and strictfp are a legal combination when defining a class, they are not a legal combination when defining a method? It says this in the latest Sierra book, I found it puzzling so I wrote an abstract class containing:

and the compiler was more than happy to accept it. So... who is right, it seems to make sense to me that you would want to enforce that an implementation of a method obeyed the strictfp rules?
Many thanks
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I compiled this under JDK 1.4.1, I got the following error:
test/Test.java [9:1] illegal combination of modifiers: abstract and strictfp
abstract strictfp float myMethod(float a);
An abstract method cannot enforce a particular implementation of itself, other than that the return type and signature must match, and the access modifier and exception specification be compatible.
Modifiers such as synchronized, native or strictfp are specific to the implementation of the abstract method, and cannot be specified when you declare an abstract method.
 
Tyler Durden
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks John, I really should have checked it on another JDK before posting, I tried it on the bundled JBuilder SDK which is 1.3.1-b24 and the following worked

Will have to download 1.4 and run all my checks against that in future. Thanks again
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
strictfp is allowed on interfaces because the public static final variables that are defined in interface will be strictfped.
Similarly if a class is defined with strictfp then strictfp is applicable to all the methods, contstructors and variables including inner classes.
strictfp can't be used with a consrtuctor.
A method with strictfp in parent class can be overridden with a method without strictfp
On abstract methods strictfp can't be used.
Am I correct? Am I missing any thing else?
[ February 11, 2003: Message edited by: Sarma Lolla ]
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok!!! so I can't define an abstract method to be strictfp!!! but by declaring the abstract class or interface as srictfp only the variables will be strictfp!!! and none of the abstract methods will be strictfp!!! (is this true???)
when you declare a strictfp class, all the methods, that are implemented,and variables in it will be strictfp!! (is it true???)
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are some parts of JLS about strictfp.


8.1.1.3 strictfp Classes
The effect of the strictfp modifier is to make all float or double expressions within the class declaration be explicitly FP-strict (�15.4). This implies that all methods declared in the class, and all nested types declared in the class, are implicitly strictfp.
Note also that all float or double expressions within all variable initializers, instance initializers, static initializers and constructors of the class will also be explicitly FP-strict.
A compile-time error occurs if a method declaration that contains the keyword abstract also contains any one of the keywords private, static, final, native, strictfp, or synchronized. A compile-time error occurs if a method declaration that contains the keyword native also contains strictfp.
If two or more method modifiers appear in a method

The presence or absence of the strictfp modifier has absolutely no effect on the rules for overriding methods and implementing abstract methods. For example, it is permitted for a method that is not FP-strict to override an FP-strict method and it is permitted for an FP-strict method to override a method that is not FP-strict.
Unlike methods, a constructor cannot be abstract, static, final, native, strictfp, or synchronized

 
John Paverd
Ranch Hand
Posts: 115
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by leandro oliveira:
ok!!! so I can't define an abstract method to be strictfp!!! but by declaring the abstract class or interface as srictfp only the variables will be strictfp!!! and none of the abstract methods will be strictfp!!! (is this true???)
when you declare a strictfp class, all the methods, that are implemented,and variables in it will be strictfp!! (is it true???)


Leandro
In addition to what Sarma said, please note that variables cannot be strictfp, only expressions can be strictfp. Declaring a class or method strictfp means that all expressions within the class or method are FP-strict, not the variables.
If you want to know exactly what FP-strict means, you can read Sections 4.2.3 and 15.4 of the JLS, but that is probably way more than you need to know for the exam.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic