• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Question

See if this.<variable> resolves to it (instance) or if <classname>.<variable> resolves to it (static) or if neither (local)

That ought to tell you.

My IDE (eclipse) tells me where a variable is defined.

Why do you need this?
 
Originally posted by: Thyme
See if this.<variable> resolves to it (instance) or if <classname>.<variable> resolves to it (static) or if neither (local)

That ought to tell you.

My IDE (eclipse) tells me where a variable is defined.

Why do you need this?

I'm a software engineering intern, and my boss wants me to write PMD (http://pmd.sourceforge.net) rules for code formatting. One of the rules is:

The class name shall always be used when referring to class (static) variables or methods. Object names shall not be used even though the Java language allows them. Unqualified references to class (static) variables shall not be used. Examples:
SomeClass.mStaticVariable; // good
SomeClass.staticMethod(); // good

SomeClass myObj;
myObj.mStaticVariable; // bad
myObj.staticMethod(); // bad

and the rule has to be written in either Java or XPath. I hate XPath (and can't find a way to accomplish it in XPath anyway). So it's Java or bust 😛

Also, I told him about "Checkstyle" another sourceforge project made specifically for this kind of thing, but he hasn't gotton back to me on that yet.
 
Ah, cool. Either Eclipse or the 1.5 JDK will generate a warning when you access a static argument in a non-static way.
 
if you ever need to do this dynamically it's easy using reflection...

Field f = Test.class.getField("tstring");
if (Modifier.isStatic(f.getModifiers()))
System.out.println("It is static");
 
Back
Top