Notes on implementing concise calls to constructors with type parameters
Maurizio Cimadamore
Maurizio.Cimadamore at Sun.COM
Thu May 14 07:43:16 PDT 2009
Ulf Zibis wrote:
> Hm, precisely I meant, if there is any difference in the instantiated
> object, and it's behaviour. Is it?
>
The instantiated object will be similar but given the class:
class Cell<X> {
X x;
Cell(X x) {this.x = x;}
}
the following code is unsafe:
Cell<String> cs = new Cell(1); //unchecked warning
String s = cs.x; //CCE at runtime
while the following is safe:
Cell<String> cs = new Cell<>(1); //compile-time error!!
String s = cs.x;
Maurizio
> I think, LHS defines precisely the variables type, it's typesafe usage
> and methodical behaviour, regardless which constructor of which type
> instantiated it, so typesafety only matters for later usage of the
> variable as typesafeness of RHS doesn't matter after that code line, and
> we can define the shortcut as legal, to avoid the compiler warning.
>
> -Ulf
>
>
> Am 13.05.2009 20:00, Neal Gafter schrieb:
>
>> The first creates a raw ArrayList, and then invokes the unchecked
>> conversion (and generating the required warning from the compiler).
>>
>> The second form is typesafe.
>>
>> On Wed, May 13, 2009 at 10:58 AM, Ulf Zibis <Ulf.Zibis at gmx.de
>> <mailto:Ulf.Zibis at gmx.de>> wrote:
>>
>> BTW 1 question:
>>
>> Is there any difference in writing:
>> List<String> l = new ArrayList();
>> or:
>> List<String> l = new ArrayList<String>();
>>
>> I guess not, so why using 2nd writing.
>>
>> thanks,
>>
>> Ulf
>>
>>
>>
>>
>>
>
>
>
More information about the coin-dev
mailing list