[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-compiler-dev
Subject:    Why cannot I write "Map<String,String> m = (Map<>)obj"?
From:       maurizio.cimadamore () oracle ! com (Maurizio Cimadamore)
Date:       2012-07-25 9:58:18
Message-ID: 500FC33A.50108 () oracle ! com
[Download RAW message or body]

On 25/07/12 10:11, Weijun Wang wrote:
> Just curious, if obj is of type Object, and I want to cast it to 
> Map<String,String>, why cannot I use the diamond operator?
Hi,
currently, diamond operator is only supported in the context of an 
instance creation expression - i.e. in the type following the 'new' 
keyword. As you point out, there are other places where diamond syntax 
might be useful - cast is one them, as the right-hand-side of a variable 
declaration, or the type of a constructor reference (in Project Lambda). 
Experiments with a very fat corpus of Java code confirmed that the 
'new'/variable type declaration cases are the most recurrent ones - down 
cast to generic types, albeit important, tends to occur less frequently 
- unchecked warnings probably play a role here.

Maurizio
>
> Thanks
> Max


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic