Notes on implementing concise calls to constructors with type parameters
Howard Lovatt
howard.lovatt at iee.org
Wed May 13 20:41:13 PDT 2009
The suggestion from Reinier that:
List<String> foo = new ArrayList();
infers ArrayList<String>, seems like a good idea to me (for one thing
it is consistent with how you use generic static methods and as Ulf
pointed out people already write this and suffer the warnings). Also
the present system, because or erasure, isn't type safe as it stands,
e.g.:
final List<String> ls = new ArrayList<String>();
final List lr = ( List ) ls;
lr.add( 1 );
System.out.println( " ls = " + ls );
and Reinier's change would if anything increase type safety.
Even if there are some minor incompatibilities, it would be worth it.
I am not a fan of the <> syntax, it looks ugly and if anything implies
raw type to me rather than inferred type. A further suggestion along
Reinier's lines, allow:
ArrayList<String> foo = new();
to be equivalent to:
ArrayList<String> foo = new ArrayList<String>();
-- Howard.
More information about the coin-dev
mailing list