Notes on implementing concise calls to constructors with type parameters
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Fri May 15 02:43:32 PDT 2009
On Fri, May 15, 2009 at 1:46 PM, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> Am 15.05.2009 10:57, Ali Ebrahimi schrieb:
>
>>
>> My answer is that using a transparent diamond operator in *instantiation
>> of generic* types by jdk7+.
>> The code
>> **Cell<String> cs = new Cell(1); *
>> if* Cell is generic class then goto GENERIC_CASE
>>
>>
>
> I guess you mean:
>
> if* new Cell(1) invokes generic type constructor then goto GENERIC_CASE
>
I mean:
if instantiated object (new Cell(1)) type(Cell) is generic class and have
generic type constructor.
example:
List<String> myList = new ArrayList();
treates as: GENERIC_CASE
List<String> myList = new ArrayList<String>();
because that ArrayList is now generic class(since 1.5).
But the following code:
List<String> myLegacyList = new MyCustomLegacyList();
is treated as: Raw_CASE
List<String> myLegacyList = new MyCustomLegacyList();
and some day I update MyCustomLegacyList class(generified it) and recompile
above code without changing code:
Compiler(jdk 1.7+) in this time must behave as below:
List<String> myLegacyList = new MyCustomLegacyList();
Must be treated as: GENERIC_CASE
List<String> myLegacyList = new MyCustomLegacyList<String>();
>
>
> **GENERIC_CASE:
>> * treated as :
>> * Cell<String> cs = new Cell<>(1); *
>>
>> and this treated as:
>>
>> * Cell<String> cs = new Cell<**String**>(1); *
>> goto Next:
>>
>> else // raw type(legacy code)
>> RAW_CASE:
>> *Cell<String> cs = new Cell(1); *
>>
>> Next:
>>
>> And finally catching compile time error.
>>
>>
>
> Better:
> And finally catching compile time error for *GENERIC_CASE*, but no error
> for *RAW_CASE*
>
> ;-)
Yes.
>
>
> -Ulf
>
>
>
More information about the coin-dev
mailing list