jeudi 1 mars 2018

Java generic parameter as exact subclass?

Assuming we have a method like this:

public void foo(Class<? extends ClassBar> x) {
    ...
}

By modifying the generic expression;

< ? extends ClassBar >

Is it possible to ensure that ClassBar.class can't be passed in but anything extends ClassBar directly or indirectly be passed in WITHOUT throwing an exception on the runtime?





Aucun commentaire:

Enregistrer un commentaire