Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cleaning up warnings

 
Robert Benson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm tidying up my project and I am removing as many warnings as possible.

There is one error that I can't resolve.




The static field JFrame.EXIT_ON_CLOSE should be accessed in a static way



My ide is giving me the option to suppress the warning. Is this accpetable?

I can 1) suppress the warning or 2) code a fix.

Option 2 is obviously cleaner and better. Any pointers for a code fix appreciated.

Regards, Robert.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all: suppressing a warning is not removing it. It's just telling your IDE not to show it in the warning overview

The warning you get is one of the easiest to fix: all static fields should be used in a static way, which means: use the interface/class name in which the constant is declared instead of using an instance of that interface/class.

So if you change your code to the following, the warning will disappear magically (just like a David Copperfield's trick ):
 
Robert Benson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel.


Nearly ready to ship but that was kind of ugly and easy enough to fix.
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So finally they are resorting to static field access
Being also a .Net programmer, I have the habit of doing the same. In C#, you are not allowed to use object references for static fields or methods. This reduces a lot of confusion. I think the IDE is trying to enforce a c# like feature without breaking any existing code.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This "feature" allows you to have tricky questions (thanks to a bit of confusion ) at the SCJP (mock) exam(s), for example.

1/


2/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic