Re: Class<T> question

Attila Szegedi <[email protected]>
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
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.

Attila.

On 2007.12.05., at 14:12, Gart, Mitchell wrote:

> I am trying to get rid of some compiler warnings in our code.  We
> have a
> method:
>
>   public static Logger getLogger(Class c) {
>      return new Log4jLogger(c.getName());
>   }
>
> and the compiler produces this warning:
>
>   Class is a raw type. References to generic type Class<T> should be
> parameterized
>
> It is because Class is a generic type but I don't quite understand
> how I
> would change the declaration of the method, and the calls to the
> method,
> to make it parameterized and get rid of the warning.  Can somebody
> explain this a little bit?  Thanks.
>
> - Mitch Gart

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.