Extra field in classes when compiling with IntelliJ

Hi all,

I'm compiling with IntelliJ, and I want to use some reflection to see all the public fields in the class. I use the following code to do so:


When I compile this with javac, I get this output:
Field name
Field address

When I compile this with IntelliJ (jdk 1.4), I get this output:
Field name
Field address
Field class$nl$wehkamp$trc$fitnesse$Test

Now my question is: when does this extra field come from? I already unchecked the 'Generate debuggin info' in the javac options, but maybe I missed something here?

Erik

3 comments
Comment actions Permalink

Hello Erik,

I'm compiling with IntelliJ, and I want to use some reflection to see
all the public fields in the class. I use the following code to do so:

 import java.lang.reflect.Field;
> public class Test {
> public String name;
> public String address;
> public static void main(String[] args) {
> Test test = new Test()
> test.test();
> }
> public void test() {
> Field[] declaredFields = Test.class.getDeclaredFields();
> for(int i = 0; i < declaredFields.length; i++ ) {
> Field field = declaredFields+;
> System.out.println("Field " + field.getName());
> }
> }
> }
> ]]>


When I compile this with javac, I get this output:
Field name
Field address
When I compile this with IntelliJ (jdk 1.4), I get this output:
Field name
Field address
Field class$nl$wehkamp$trc$fitnesse$Test
Now my question is: when does this extra field come from? I already
unchecked the 'Generate debuggin info' in the javac options, but maybe
I missed something here?


This is a field for the class literal. It's added by javac, not IntelliJ
IDEA. Handling of class literals changed between different versions of javac,
so you simply see the result of a javac version difference.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Oops, my mistake then! Thanks for the quick reply!

0

Please sign in to leave a comment.