Java 9 ea154 javac compiler error - legit or bug?
Vitaly Davidovich
vitalyd at gmail.com
Wed Feb 8 19:23:48 UTC 2017
Hi all,
Given the following code:
import java.util.ArrayList;
import java.util.Collection;
public class Foo {
static <T> T foo(Class<T> c, Collection<? super T> baz) {
return null;
}
static void bar(String c) {
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
// this works
bar(foo(String.class, new ArrayList<String>()));
// this works with a warning
String s = foo(String.class, new ArrayList());
bar(s);
// this causes an error on JDK9
bar(foo(String.class, new ArrayList()));
}
}
javac 9-ea (build 9-ea+154) fails with this interesting error (on the last
line in main, as the comments there indicate):
Foo.java:23: error: method bar in class Foo cannot be applied to given
types;
bar(foo(String.class, new ArrayList()));
^
required: String
found: String
reason: argument mismatch; Object cannot be converted to String
1 error
Java 8 compiles fine, and the other 2 lines compile in the same java 9
build as well.
Is this a javac bug or legit? It seems like a compiler error. At a
minimum, the diagnostic output "required String, found String" is confusing.
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20170208/9c987ed5/attachment-0001.html>
More information about the compiler-dev
mailing list