compiler creates generated fields/methods when class switches on enum [message #530147] |
Wed, 28 April 2010 12:33  |
Eclipse User |
|
|
|
I am seeing behavior similar to this thread, http://forums.sun.com/thread.jspa?threadID=5417665
I have a simple class that switches on an enum (included at the bottom of this message).
If I compile within eclipse, and then look at the declared methods/fields using this class file, I see the generated SWITCH_TABLE methods.
This only occurs if i comple within eclipse. If I use javac, i do not see these methods/fields in the class.
Is there a way to disable?
here is an example
If I print out the declared methods against the eclipse generatd class I see
$SWITCH_TABLE$Simple$SortOrder
convertSortOrder
And the field is
field $SWITCH_TABLE$Simple$SortOrder
If I print this information out against a class built outside of eclipse with javac, I only see the declared method, convertSortOrder.
I am printing out the declared methods/fields as follows:
Method[] methods = Simple.class.getDeclaredMethods();
for (int i=0; i < methods.length; i++)
{
System.out.println(methods[i].getName());
}
Field[] fields = Simple.class.getDeclaredFields(); for (int i=0; i < fields.length; i++) {
System.out.println("field " +fields[i].getName()); }
This is the Simple class that switches on the enum:
import java.io.Serializable;
public class Simple implements Serializable {
public static enum SortOrder
{
START_DATE, END_DATE, PROCESS_TITLE
};
public String convertSortOrder(SortOrder sort)
{
String retStr = null;
switch (sort)
{
case PROCESS_TITLE:
retStr = "process";
break;
}
return retStr;
}
}
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02709 seconds