• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method calls static Math class method on a constant value  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I receive the warning "Method calls static Math class method on a constant value" (line 1) with this code in my main Method after doing "Source, Inspect" in NetBeans IDE 8.2:

Is there a solution for this?
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Well, think about why that warning would be given for minute.  If someone came to you and asked, "What's 2 + 2?" and you answered, "4" and then 2 minutes later they come back and asked you the same question, and then later, the same question, over and over again, what would you think? The analyzer is seeing the same kind of situation here.

Programs are more useful when the data they have to deal with varies. In other words, variable data. You are giving Math.ceil() a constant value.
 
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...but if the program is an exercise in trying out how Math#ceil works, then you would find the warning just as annoying . Every now and again I think maybe the IDEs have got too clever for their own good.
And welcome again
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True. You can just ignore the nag or you can take it as a challenge to find a better way to formulate your little experiment.

This will probably get rid of the analyzer's nagging.
 
Reivilo Sleid
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Junilu Lacar and Campbell Ritchie!

You are right.  I only used the two lines of code for testing something of the Math class and see the result.
And yes, the warning is annoying.

I've adapted my two lines of code to this:


No warning anymore!  Thank you for your good explanation.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!