Java Generics: overriding common methods, wildcards?

If I have an interface with a common method, for example:

public interface Thing {
    void <T extends Comparable<? super T>> doSomething(List<T> objects);
}

I need this ugly generic typespec in some places, but it really doesn't need most implementations:

public class ICareAboutSortingThing implements Thing {
    @Override
    public void <T extends Comparable<? super T>> doSomething(List<T> objects) { ... }
}

public class IDontCareAboutSortingThingx100 implements Thing {
    @Override
    public void <T extends Comparable<? super T>> doSomething(List<T> objects) { ... }
}

What I would like to write is something like:

public class IDontCareAboutSortingThingx100 implements Thing {
    @Override
    public void <?> doSomething(List<?> objects) { ... }
}

This should be completely typical, as I understand it, but are there any changes to these kinds of reductions that will work? I understand that the compiler does not allow overriding non-generic methods, but this is a case of replacing type arguments with wildcards. I guess this is not actually supported, because the compiler can just as easily support

public class IDontCareAboutSortingThingx100 implements Thing {
    @Override
    public void <T> doSomething(List<T> objects) { ... }
}

. , , , . , , - .

+4
3

, , . :

interface I {
    void m(String s);
}

class C implements I {
    @Override
    public void m(Object o) {}
}

void(Object) void(String), . Java .

, :

class NotGeneric implements Thing {
    @Override
    public void doSomething(List rawList) {}
}

. raw type, . .

, , , .

- , ,

interface NonGenericThing extends Thing {
    @Override
    default <T extends Comparable<? super T>>
    void doSomething(List<T> list) {
        doSomethingImpl(list);
    }
    void doSomethingImpl(List<?> list);
}

NonGenericThing doSomethingImpl. ( Java 8, NonGenericThing .)

, , Thing . Thing , .

+1

, , ?

public class It<T extends Comparable<? super T>> {

    public List<T> them;
}

public interface Thing {

    void doSomething(It<String> them);
}
+4

:

public class IDontCareAboutSortingThingx100<T extends Comparable<? super T>> implements Thing<T> {

    @Override
    public void doSomething(List<T> objects) {
    }
}
0

All Articles