0
votes

with the given 2 classes:

public class A{
    public <T> Cell<T> f(Cell<T> l){
        return null;
    }
}
public class B extends A{
    public <T> Cell<T> f(Cell<Cell<T>> l){ // trying to override
        return null;
    }
}

(when Cell is some generic class).

i understand that after type erasure, the classes looks like:

public class A{
    public Cell f(Cell l){
        return null;
    }
}
public class B extends A{
    public Cell f(Cell l){ // trying to override
        return null;
    }
}

before i knew the type erasure thing, i think that i did understand why the compiler sees it as an overloading.

but now that i (think that) i know about the type erasure, the two method signatures are the same, and i really think that it makes much more sense that the compiler will see this as an OVERRIDING.

after compiling it, got that java's compiler saw this as a trying to OVERLOAD and not override, and yields an error for overloading to identical-signatured methods.

my question: why the compiler still sees this as a trying of OVERLOADING and not OVERRIDING, although after type erasure the signatures are just the same?

thanks!

1

1 Answers

0
votes

The error "overloading with same signature" seems adequate here. It is not technically overriding because to the compiler generics matter and B's f does not satisfies A's signature as A's f T is not restricted to implement Cell<?> so B's f is not overriding A's f; it makes more sense to call it "overloading" instead because generic-wise those signatures are different despite end up being the same after erasure.

I reckon that the "overloading with same signature" error was added for this particular scenario with generics resulting in conflicting erasures.