Local variable inference and anonymous class

Brian Goetz brian.goetz at oracle.com
Thu Nov 16 07:45:06 UTC 2017


This is like using an Object[], but with names and no second level of boxing…

> On Nov 16, 2017, at 4:10 AM, John Rose <john.r.rose at oracle.com> wrote:
> 
> On Nov 15, 2017, at 5:15 PM, Remi Forax <forax at univ-mlv.fr <mailto:forax at univ-mlv.fr>> wrote:
>> 
>>    List<String> list = List.of("hello", "world!");
>>    Map<Integer, String> map = list.stream()
>>      .map(s -> new Object() { int key = s.length(); String value = s; })
>>      .collect(Collectors.toMap(t -> t.key, t -> t.value));
>>    System.out.println(map);
>> 
>> so i guess 'leaking' the type of an anonymous class is not an issue.
> 
> That's cool; I didn't know Java had anonymous tuples!!!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20171116/ed62c386/attachment.html>


More information about the amber-spec-experts mailing list