I have to different constants,
final List<Class<? extends Some>> CLASSES1 = List.of(...);
final List<Class<? extends Other>> CLASSES2 = List.of(...);
and a method.
static void doSome(final List<Class<?>>) classes) {
}
When I try to invoke with either CLASSES
or CLASSES2
, the compiler complains.
java: incompatible types:
java.util.List<java.lang.Class<? extends Some>>
cannot be converted to java.util.List<java.lang.Class<?>>
How can I fix this?
All I can do is this.
doSome(new ArrayList<>(CLASSES1));
Do I have other way?
I have to different constants,
final List<Class<? extends Some>> CLASSES1 = List.of(...);
final List<Class<? extends Other>> CLASSES2 = List.of(...);
and a method.
static void doSome(final List<Class<?>>) classes) {
}
When I try to invoke with either CLASSES
or CLASSES2
, the compiler complains.
java: incompatible types:
java.util.List<java.lang.Class<? extends Some>>
cannot be converted to java.util.List<java.lang.Class<?>>
How can I fix this?
All I can do is this.
doSome(new ArrayList<>(CLASSES1));
Do I have other way?
Share Improve this question asked Mar 23 at 10:01 Jin KwonJin Kwon 22.1k18 gold badges129 silver badges210 bronze badges 2- What can you change? Can you change the types of the constants? Can you change the method's parameter type? – Sweeper Commented Mar 23 at 10:04
- 1 This question is similar to: What is PECS (Producer Extends Consumer Super)?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. – Sören Commented Mar 23 at 12:04
1 Answer
Reset to default 1I changed the method like this,
static <T> void doSome(final List<Class<? extends T>>) classes) {
}
And it seems work.
doSome(CLASSES1);
doSome(CLASSES2);