Stewie Stewie - 1 year ago 67
Java Question

Abstract and concrete method with same signature in generic class

In JLS 8, Section there is a statement:

A concrete method in a generic superclass C can, under certain parameterizations, have
the same signature as an abstract method in that class. In this case, the concrete method
is inherited and the abstract method is not. The inherited
method should then be considered to override its abstract peer from C.

Could anyone provide an example of such parametrization for generic class? I was not able to.

Answer Source


public abstract class A<T> {
    public abstract void m(T t);

    public void m(String s) {}

public class B extends A<String> {

In this case both methods in B will be void m(String).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download