This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Running a Java Program


My opinion is that gij has the bug. B inherits main from A, and JLS 12.1.4 states that the "method main of [B] is invoked" if the VM was started on class B. It does not state that B had to _declare_ main, just that B has to have a public, static, void main that accepts an array of Strings. The JVMS has similar permissive wording for the VM startup, in 5.2.

Further, the JVMS description of invokestatic states that trying to invoke B.main will cause method resolution, documented in 5.4.3.3, which must find A.main if B does not declare main. This is designed in part for binary compatibiliy with this three-class example:
class A {
static void m() {}
}
class B extends A {
static void m() {}
}
class C {
{ B.m(); }
}


When compiled together, C refers to B.m(), but B can be recompiled to remove m(), and C will still work without recompilation by resolving to A.m().

In conclusion, I think class B is adequate for gij to start executing, because gij should behave as though an invokestatic and method resolution finds the inherited A.main().

Ranjit Mathew wrote:
Hi,

    Today I came across this weird behaviour in the
Sun JRE that is not present in gij. Consider these:
------------------------- 8< ----------------------------
public class A
{
  public static void main( String[] args)
  {
    System.out.println( "Hello World!");
  }
}
------------------------- 8< ----------------------------
public class B extends A
{
}
------------------------- 8< ----------------------------

Compile these files to bytecode.

If I run "java B" Sun's JRE (both 1.3.1 and 1.4.2)
goes ahead and runs the main( ) from class A!

If I run "gij B" it (rightly, IMHO) prints out:

no suitable method `main' in class

This is also rejected by Oracle's new JDeveloper 10g preview
while the older version allowed this to happen (that's
how I discovered it).

What do you guys think is the correct behaviour?
Should we bother emulating Sun in this even though
it is not even documented in the main "java"
tool documentation?

Ranjit.


-- Someday, I might put a cute statement here.

Eric Blake ebb9@byu.net


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]