lambda expression not expected here
Brian Goetz
brian.goetz at oracle.com
Sat Jun 1 10:56:08 PDT 2013
You've mostly got it. A lambda expression needs a type, since it is compatible with many types. It can get its target type from an assignment context, a method invocation context, a cast context, etc.
You are right the error message could be better.
On Jun 1, 2013, at 10:29 AM, Marc Petit-Huguenin wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Hi,
>
> The compilation of this code fails with a "lambda expression not expected
> here" error:
>
> int i = (f -> f + 1).applyAsInt(1);
>
> I am not sure to understand why this code is invalid as the following code
> compiles fine:
>
> int i = ((IntUnaryOperator)(f -> f + 1)).applyAsInt(1);
>
> If it is because the compiler cannot infer the type, then perhaps the error
> text could be improved.
>
> Thanks.
>
> - --
> Marc Petit-Huguenin
> Email: marc at petit-huguenin.org
> Blog: http://blog.marc.petit-huguenin.org
> Profile: http://www.linkedin.com/in/petithug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
>
> iQIcBAEBCAAGBQJRqi97AAoJECnERZXWan7E+CsP/14IlYCyFkJsHuP8M1KAp38c
> ZGiCqyU2zkKGFdZuMNeslUD25NoLjLpBfNRlk1d4kWZzo+zFWKEnnE/wVJB49zRE
> bG4W9iS0ToktODLfDqawPHb4OAEurrqosA3BzUrAy/C7KoOISvvZwVIbXRO/zQi5
> I7/s3G5rb3aN84J6tYjVt0zIKhtBls45slpP+mN9gA8y/u+EZwtQgZc1WhAnKv73
> g5iBCvQK68m9bgj/sCs0W/Y60bRD6vpF3QR26z6mFFfT2Q7ykmSbIb0bF2GteFbr
> coRYM/Y6FtmAayPduSbTS3gDS9GuiHnnvJzwuM9Wgd/f/FkbDnhR8wXNdEoXh+ry
> klRteAHDzXgOrqHqOfDvWx9JgYqNi7bVw45H8AbsmJj20cdq0Amy8JWEh3iTD6Zy
> o6aR0iUpDeQ7Kg+IIn0lzccqBnh6+FKqZqsn5mIpNvPULeHTyu2B54AOUi52Kpez
> xDTiioUaRXLZynWpG2AghWTJqc2uZM7T81O+pPSZLPSaHVC7Dde+IU4KG+PvbuHx
> 84Rsl7h9wh4pnoxYFcC4WTCinBoF2KZ7MWqT9bUCQGI99FGUvqF4wN76t9tMytbC
> YztxzG8q3EHXThxH120dk3HhzyXUj5r4wqmHphH0r9kFN1N8u/Z+lELF4nJa/KCc
> BU9BWzp6qbKMt0PSJ7Dl
> =YAKJ
> -----END PGP SIGNATURE-----
>
More information about the lambda-dev
mailing list