Re: Class<T> question
Jeff Kesselman <[email protected]> Wed, 5 Dec 2007 11:48:12 -0500
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
I look at generics like any other tool. Used right theya re handy but they arent the answer to every issue. JK James Childers wrote: > On Dec 5, 2007, at 9:48 AM, Attila Szegedi wrote: > >> In my recent wrestling with "genericizing" a codebase that was >> originally pre-Java 5, I'd suggest you try replacing "Class" with >> "Class<?>". >> >> Alternatively, disable compiler warning for generics. No, seriously. >> Honestly, my feeling is that programming with generics causes more >> noise in source code than it eliminates. Yeah, it eliminates casts, >> but previously I would write: >> >> Map map = new HashMap(); >> ... >> String x = (String)map.get(blah); >> >> Now I write monstrosities such as: >> >> Map<? extends Object, String> map = new HashMap<Object, String>(); >> ... >> String x = map.get(blah); >> >> So, I need to write one cast less, and four type specifiers more. Net >> loss in code conciseness. >> I guess I'm just getting old and resistant to change. > > Java generic syntax is notoriously verbose. Neil Gafter recently > offered a couple of proposals for a more concise syntax: > > http://gafter.blogspot.com/2007/07/constructor-type-inference.html > > From his proposals: > > map := new HashMap<String,List<Thing>>(); > > Or alternatively: > > Map<String,List<Thing>> map = new HashMap<>(); > > In the former case the assigned type is HashMap, which prevents > programming to interfaces. It also introduces a new operator. > > The second case simply relies upon inference of the proper generic > types. > > -= James > > =================================== > This list is hosted by DevelopMentor® http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com