cast at call site problem

Anna Kozlova Anna.Kozlova at jetbrains.com
Wed Apr 3 03:38:45 PDT 2013


What are reasons behind that then?

-----Original Message-----
From: lambda-dev-bounces at openjdk.java.net
[mailto:lambda-dev-bounces at openjdk.java.net] On Behalf Of Maurizio
Cimadamore
Sent: Wednesday, April 03, 2013 11:54 AM
To: Anna Kozlova
Cc: lambda-dev at openjdk.java.net
Subject: Re: cast at call site problem

On 01/04/13 15:59, Anna Kozlova wrote:
> The call foo(Collections.emptySet()); is much more clean I suppose. I 
> just wonder why the redundant cast leads to compilation error.
As per spec EDR, a cast does not pass its type down to the expression being
converted. This means that the call to emptySet is typed with an Object
target; hence the error. If you remove the cast, the right target is used.

Maurizio
>
> Thanks
>
>   
>
> From: paulus.benedictus at gmail.com [mailto:paulus.benedictus at gmail.com] 
> On Behalf Of Paul Benedict
> Sent: Monday, April 01, 2013 4:51 PM
> To: Anna Kozlova
> Cc: lambda-dev at openjdk.java.net
> Subject: Re: cast at call site problem
>
>   
>
> I believe you want to write this:
> foo(Collections.<String>emptySet());
>
>   
>
> On Mon, Apr 1, 2013 at 9:48 AM, Anna Kozlova 
> <Anna.Kozlova at jetbrains.com>
> wrote:
>
> Hello all,
>
> Is it a bug or is it an intentional behavior:
> This code compiles
> {code}
>      void foo(Set<String> s) {}
>
>      void bar() {
>          foo(Collections.emptySet());
>      }
> {code}
>
> but this code doesn't:
> {code}
>      void foo(Set<String> s) {}
>
>      void bar() {
>          foo((Set<String>)Collections.emptySet());
>      }
> {code}
>
> Lambda build 83.
>
> Thanks
> Anna
>
>
>
>
>   
>
> 
>
>



!DSPAM:35,515bfca371141724266025!



More information about the lambda-dev mailing list