Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[])" [message #225920] |
Thu, 16 March 2006 13:05  |
Eclipse User |
|
|
|
I'm using Eclipse 3.1.2 on WinXP, with JDK 1.4.2
As an experiment, I created an Eclipse project from the "java-puzzlers"
source distribution. I then selected one of the source files,
"Change.java" and tried to run it. It said:
java.lang.NoSuchMethodError: main
Exception in thread "main"
That seemed pretty odd. I looked carefully at the class, and I didn't see
anything wrong with it. I then tried running "javap" on the class file,
and it showed me the following:
------------
Compiled from "Change.java"
public class Change extends java.lang.Object{
public Change();
Code:
0: aload_0
1: invokespecial #9; //Method java/lang/Object."<init>":()V
4: return
public static void main(String[]);
Code:
0: getstatic #21; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc2_w #22; //double 0.8999999999999999d
6: invokevirtual #29; //Method java/io/PrintStream.println:(D)V
9: return
}
------------
This still seemed ok to me. Just in case, I tried executing the class
directly from the command line, using my 1.4.2 JDK. It got the same error.
Then, I tried compiling the source file directly from the command line,
using my 1.4.2 JDK. When I tried to execute this, it worked fine, not
reporting that error. I then ran "javap" again on this class, and got the
following:
-------------------
Compiled from "Change.java"
public class Change extends java.lang.Object{
public Change();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc2_w #3; //double 0.8999999999999999d
6: invokevirtual #5; //Method java/io/PrintStream.println:(D)V
9: return
}
-------------------
There's only one difference in the two "javap" listings, the type of the
formal parameter to "main". The one that works is "java.lang.String[]",
and the one that fails is "String[]".
What's going on here?
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.29819 seconds