Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:00:56+00:00 2026-06-10T11:00:56+00:00

While refactoring some code I stumbled over this oddity. It seems to be impossible

  • 0

While refactoring some code I stumbled over this oddity. It seems to be impossible to control the strictfp property for an initializer without affecting the entire class. Example:

public class MyClass {

    public final static float[] TABLE;
    strictfp static { // this obviously doesn't compile
         TABLE = new float[...];
         // initialize table
    }

    public static float[] myMethod(float[] args) {
         // do something with table and args
         // note this methods should *not* be strictfp
    }

}

From the JLS, Section 8.1.1.3 I gather that the initializer would be strictfp if the class would be declared using the strictfp modifier. But it also says it makes all methods implicitly strictfp:

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 (§15.4).

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

So, the modifier is not accepted for the static initializer, and when applied to the entire class, everything becomes strictfp? Since there is no opposite to the strictfp keyword, this is impossible to achieve?

So, am I screwed to use a static method to hold the body of the initializer block to achieve precise control over strictfp’dness?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:00:57+00:00Added an answer on June 10, 2026 at 11:00 am

    Using the requirements that:

    • the initialization code is called once,
    • the MyClass.myMethod method is non-strict floating-point,
    • the class API is not “littered” with methods,
    • and the initialization code is strict floating-point

    … this will suffice:

    class MyClass {
      //1) initialized/called once
      public final static float[] TABLE = MyClassInitializer.buildSomething();
    
      public static float[] myMethod(float[] args) {
        //2) non-strict
      }
    }
    
    //3) doesn't "pollute" the MyClass API
    class MyClassInitializer {
      strictfp [static] float[] buildSomething() { //4) strictfp here or on the class
        //TODO: return something
      }
    }
    

    If you think of the static members of a class as objects in a separate, singleton object, the above example will seem natural. I think this plays very nicely with the Single Responsibility Principle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While refactoring some code, I came across this strange compile error: The constructor call
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I
I unfortunately was doing a little code archeology today (while refactoring out some old
While refactoring some old code I have stripped out a number of public methods
While refactoring some C# classes, I've run into classes that implement IDisposable. Without thinking,
Possible Duplicate: conditional statement and assigning value in ruby While refactoring some rails code,
While doing some refactoring I've found that I'm quite often using a pair or
While refactoring my code base I found a piece of code which I'd like
Recently I have been refactoring some of my C# code and I found a
I'm refactoring some code and I have written a method that modifies a Dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.