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: Error: Non-static method overrides static method


>>>>> "Robin" == Robin Rawson-Tetley <enquiries@sheltermanager.homeip.net> writes:

Robin> It seems that GCJ barfs if a subclass redeclares a method with the same
Robin> name as a static method in the base class. Under regular javac, this is 
Robin> allowed and is no problem (since you have to call the methods in two 
Robin> different ways).

Actually, this is invalid according to the Java Language Spec.  See:

http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#228745

  A compile-time error occurs if an instance method overrides a static
  method.

Elsewhere (in 8.4.6.2), it also mentions that it is an error if a
static method hides an instance method.

These definitions all look at accessibility, though, so in some
situations you can have methods with the same name and signature
without getting an error.


Furthermore, it is a little-known corner of the Java language that
you can write:

    expr.method ();

... where `method' is a static method.  This evaluates `expr' for side
effects and then calls the static method.  Goofy, perhaps useless, but
there it is.

Tom


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