jls overridding description

Dan Smith daniel.smith at oracle.com
Tue May 19 21:27:45 UTC 2015


> On May 6, 2015, at 9:27 AM, konstantin barzilovich <konstantin.barzilovich at oracle.com> wrote:
> 
> Hello,
> 
> In Chapter 8 of jls there is assertion jls-8.4.8.1-100
> "An instance method mc, declared in or inherited by class C, overrides from C another method ma, declared in class A, iff all of the following are true: "
>  which describe conditions of overriding of classes methods. As I understand, one of jls-8.4.8.1-100-B
> "C doesn't inherit ma"
>  and jls-8.4.8.1-100-C
> "The signature of mc is a subsignature of the signature of ma"
>  is redundant because if we omit, for example, jls-8.4.8.1-100-C,
> no cases will be missed.

You're appealing to this (8.4.8):

"A class C inherits from its direct superclass all concrete methods m (both static and instance) of the superclass for which ... no method declared in C has a signature that is a subsignature (§8.4.2) of the signature of m."

and

"A class C inherits from its direct superclass and direct superinterfaces all abstract and default (§9.4) methods m for which ... 	no method declared in C has a signature that is a subsignature (§8.4.2) of the signature of m, [and] no concrete method inherited by C from its direct superclass has a signature that is a subsignature of the signature of m"

And, additionally, this (8.4.2):

"It is a compile-time error to declare two methods with override-equivalent signatures in a class."

So, how can 'mA' be inherited by C, yet 'mC' have a subsignature of the signature of 'mA'?  First, 'mC' must not be declared in C.  Second, the declaration of 'mC' must not be override equivalent with 'mA'.

Typically, you get there with generics:

abstract class A<T> {
    abstract void m1(T arg);
    abstract void m2(String arg);
}

abstract class C extends A<String> {}

Now m1 and m2 are both inherited by C and have the same signature (in C).  But we do not want to claim that one overrides the other -- they just coexist in the same class (see also 8.4.8.4 and 15.12.2.5).  You could also get there with two concrete methods, although that would be an error.

(BTW, sorry for not seeing this sooner.  I don't always read every post to compiler-dev, so feel free to ping me if there's something like this you're waiting for a response on.)

—Dan


More information about the compiler-dev mailing list