[3850] in java-interest

home help back first fref pref prev next nref lref last post

method overriding suggestion

daemon@ATHENA.MIT.EDU (Felix Wu)
Wed Nov 29 21:43:33 1995

Date: Wed, 29 Nov 1995 15:44:47 -0800
From: Felix Wu <wu@cadence.com>
To: java-interest@java.Eng.Sun.COM
Cc: wu@cds769.Cadence.COM

I have a small suggestion with regard to method overriding that is somewhat
related to the recent discussions among David Griswold, Jim Graham, Bill Joy,
and others.

Add a keyword like "overrides" to signify a user's intention of overriding
some method. This should make the code more readable, and the compiler could
issue a warning message if there is no matching method to override (instead
of silently adding it as a new, possibly overloaded, method).

Also, the (explicitly requested) overridding method could have a signature
that's more specific than the overridden one. The compiler could add a little
wrapping code to make its signature the same as the overridden one. 

For example, the following overriding 'equals' method

      class C extends Object {
    
        overrides boolean equals(C obj) { ... }
      }

could be rewritten (implicitly by the compiler) as

      [overrides] boolean equals(Object obj)
      {
         if (obj instanceof C) {
	    ... // the original code
	 } else {
	    return super.equals(obj);
	 }
      }

And presumably, all this could be done as compatible extension to the
current Java design.

- Felix Wu
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post