Three compilation errors involving closure literals
Neal Gafter
neal at gafter.com
Sat May 17 13:19:42 PDT 2008
Mark-
Thanks for these reports! I'm currently working on promoting the code base
into openjdk, but once that is done I'll start addressing these issues.
Regards,
Neal
On Sat, May 17, 2008 at 1:08 PM, Mark Mahieu <mark at twistedbanana.demon.co.uk>
wrote:
> Here are three classes I'd expect to be considered valid, but which don't
> compile. Not sure if I've mentioned any of these previously, apologies if
> so.
>
>
> 1) Using a closure literal on the rhs of the == and != operators yields an
> "incomparable types" error:
>
>
> public class IncomparableTypes {
>
> public static void main(String[] args) {
>
> {=> void} block = {=>};
>
> boolean result;
> result = {=>} == block;
> result = block == {=>};
> }
> }
>
>
> IncomparableTypes.java:9: incomparable types: { => void} and { => void}
> result = block == {=>};
> ^
> 1 error
>
>
>
> 2) Using a closure literal as the expression operand of the instanceof
> operator results in an "unexpected type" error:
>
>
> public class UnexpectedType {
>
> public static void main(String[] args) {
>
> boolean result = {=>} instanceof Object;
> }
> }
>
>
> UnexpectedType.java:5: unexpected type
> found : { => void}
> required: reference
> boolean result = {=>} instanceof Object;
> ^
> 1 error
>
>
>
> 3) Casting a closure literal is also rejected:
>
>
> public class Cast {
>
> public static void main(String[] args) {
>
> foo((Object) {=> "Hello"});
> }
>
> static void foo(Object o) { }
>
> static void foo({=>Object} fn) { }
> }
>
>
> Cast.java:5: ')' expected
> foo((Object) {=> "Hello"});
> ^
> Cast.java:5: not a statement
> foo((Object) {=> "Hello"});
> ^
> Cast.java:5: ';' expected
> foo((Object) {=> "Hello"});
> ^
> 3 errors
>
>
>
> Regards,
>
> Mark
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20080517/e036846e/attachment.html
More information about the closures-dev
mailing list