You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Test {
static final class Expression<T> {
Class<T> getType() {
throw new RuntimeException("xxx");
}
}
private static void validate(List<? extends Class<?>> argumentTypes) {
throw new RuntimeException("xxx");
}
void test(Collection<? extends Expression<?>> arguments) {
var argumentTypes = arguments.stream().map(Expression::getType).toList();
validate(argumentTypes);
}
}
reports
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:24:14
java: [argument] incompatible argument for parameter argumentTypes of Test.validate.
found : @UnknownKeyFor List<R[ extends @UnknownKeyFor Object super @KeyForBottom Void]>
required: @UnknownKeyFor List<?[ extends @UnknownKeyFor Class<?[ extends @UnknownKeyFor Object super @UnknownKeyFor Void]> super @KeyForBottom Void]>
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:24:14
java: [argument] incompatible argument for parameter argumentTypes of Test.validate.
found : @Initialized @NonNull List<R extends @Initialized @Nullable Object>
required: @Initialized @NonNull List<? extends @Initialized @NonNull Class<? extends @Initialized @Nullable Object>>
It seems checker is unable to infer correct type, JDK is able to compile the code and problem is not nullability, but missing information in checker type inference.
To be honest, I do not completely understand even JDK type inference here, as if I replace var with what I think should pass for actual type List<Class<?>> argumentTypes = arguments.stream().map(Expression::getType).toList();
compilation fails with
java: incompatible types: java.util.List<java.lang.Class<capture#1 of ?>> cannot be converted to java.util.List<java.lang.Class<?>>
I get originally mentioned warning with List<? extends Class<?>> argumentTypes = arguments.stream().map(Expression::getType).toList();
The text was updated successfully, but these errors were encountered:
Following example
reports
It seems checker is unable to infer correct type, JDK is able to compile the code and problem is not nullability, but missing information in checker type inference.
To be honest, I do not completely understand even JDK type inference here, as if I replace var with what I think should pass for actual type
List<Class<?>> argumentTypes = arguments.stream().map(Expression::getType).toList();
compilation fails with
java: incompatible types: java.util.List<java.lang.Class<capture#1 of ?>> cannot be converted to java.util.List<java.lang.Class<?>>
I get originally mentioned warning with
List<? extends Class<?>> argumentTypes = arguments.stream().map(Expression::getType).toList();
The text was updated successfully, but these errors were encountered: