This might sound like an odd question but how can on define a generic which has to extend a class AND to implement an interface? Im currently having a generic function with the following prototype:
public static <E extends Enum<E>> List<E> buildEnumList(Class<E> enumClass)
This works just as intented. My problem now is that I want to further restrict the passable classes to those which are enums and implement a specific interface Readable
(not that in java.lang). Since a generic uses the same keyword extends
to indicate that it should implement an interface, I dont see any way to get the following pseudo behaviour:
public static <E extends Enum<E> implements Readable> List<E> buildLexicographicalEnumList(Class<E> enumClass)
You can use &
to indicate that E
must also implement an interface:
public static <E extends Enum<E> & Readable> List<E> buildLexicographicalEnumList(Class<E> enumClass) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With