Q:

Method in Java interface that returns class or subclass type

I have an interface:
public interface Displayable {
    public Class <Screen> classToDisplay();
}

and some classes:
public class Screen {

}

public class ScreenSubclass extends Screen {

}

public class Cue implements Displayable {

    @Override displayClass() {
        return ScreenSubclass.class;
    }

}

I'm getting an IDE error telling me they are incompatible types. What return value would be needed for 'classToDisplay()' to return a class or subclass type of Screen?

A:

Just figured it out. Use the ? wildcard along with 'extends'...
Change the return type for 'displayClass' to:
public Class<? extends Screen> displayClass();

