Diamond and Generic Methods

Jesper Öqvist jesper.oqvist at cs.lth.se
Thu May 5 09:31:15 PDT 2011


On 2011-05-05 17:42, Ulf Zibis wrote:
> Am 05.05.2011 17:06, schrieb Jesper Öqvist:
>> So, after searching the archives and scouring the JSR334 v0.875 draft, I
>> have a question about Diamond. While the specification draft does not
>> explicitly disallow it, it seems weird that this works (Java7 developer
>> preview b139):
>>
>> class C {
>> <T>  void identity(T a) { return a; }
>
> Hm, is it correct, that a void method can return a value ?
>
> -Ulf

Well d'oh!
In my test case I had the equivalent of

<T> T identity(T a) { return a; }

I cleaned it up to make it as concise as possible to post it here on the 
mailing list and replaced that T for a void by mistake.

/Jesper

>
>>     void m() {
>>       identity(new java.util.ArrayList<>());
>>     }
>> }
>>
>> Since there is a distinction between raw types and parameterized types
>> with inferred type arguments (in the discussion part of the Diamond
>> section in JSR334), it would be interesting to know what type is
>> instantiated in the above example.
>>
>> /Jesper
>>
>>




More information about the coin-dev mailing list