Why does this override not compile when <T> is present?

45 Views Asked by At

This override does not compile, but when the type parameter T is removed from the overriding method it compiles fine. Why?

class Base {

    public <T> Collection<String> transform(Collection<String> list) {
        return null;
    }
}

class Derived extends Base {
    @Override
    public <T> Collection<String> transform(Collection list) {
        return null;
    }

}
1

There are 1 best solutions below

3
Oskar On

You forgot Collection in the method parameter.

Version that may be compiled:

class Base {

        public <T> Collection<String> transform(Collection<String> list) {
            return null;
        }
    }

    class Derived extends Base {
        @Override
        // Here
        public <T> Collection<String> transform(Collection<String> list) {
            return null;
        }
    }