Java 8 language spec flaw/bug
Zhong Yu
zhong.j.yu at gmail.com
Fri Aug 22 02:54:58 UTC 2014
Since we have forfeited the bottom-up principle in java8, expressions
appear to be more ambiguous to programmers. One programmer reading the
example code may as well try to parse it top-down, and come to the
conclusion that T cannot be resolved. Another programmer may have the
opposite conclusion. In that sense, the code is "practically
ambiguous", regardless what the spec actually says. Therefore the
choice of rejecting the code is not unreasonable.
One workaround is to loosen the signature of foo(Class<T>) to
foo(Class<? extends T>). One may object the change because the new
signature is not semantically as precise as the old one. We can
counter that by saying the method is likely subject to type inference
therefore it's nice to give the compiler a little more room to work
with.
Zhong Yu
bayou.io
More information about the lambda-dev
mailing list