什么,如果可能的话,将是一个很好的解决方案,以实现我想要的以下所需的功能:
// Foo and Bar are two types of Common
interface Common{}
interface Foo extends Common {}
interface Bar extends Common {}
// Example interface
public List<? extends Common> getFeatureByType(Class<? extends Common> clazz);
// Example of what I want to achieve by using the (or a similar) interface.
// Can this be achieve without using typecasting to (List<Bar>) or (List<Foo>)
// and @SuppressWarning("unchecked") ?
List<Bar> bars = getFeatureByType(Bar.class);
List<Foo> foos = getFeatureByType(Foo.class);
Run Code Online (Sandbox Code Playgroud)