File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes informal poll: how are you using generics? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "informal poll: how are you using generics?" Watch "informal poll: how are you using generics?" New topic

informal poll: how are you using generics?

Bert Bates

Joined: Oct 14, 2002
Posts: 8898
For sure I'm a fan of stuff like this:

List<Dog> d = new ArrayList<Dog>();

But I never make my own generic classes...

How about you guys, what parts of generics do you actually use?

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
subhajit paul

Joined: Dec 17, 2008
Posts: 17
A topic I myself wanted to post today(I am not sure whether I am hijacking the topic)

I was developing an implementation of Queue like

and thats when the compiler threw an error,
Array of Generic

I checked out thet there is a detour like

but in that case i cannot use it for storing primitive types(of course without using wrappers).

Is there a way around?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Java generic type parameters can't stand for primitives, anyway: you can't make a List<int> .

But yes, you can't make an array of generic type. That's because generics are "implemented by erasure", meaning that at the bytecode level, the type information is removed and the actual references are of type Object.

[Jess in Action][AskingGoodQuestions]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Some time ago, shortly after Generics came out, I ever wrote a configuration-less ORM purely for private/hobby purposes, which maps between DB and Java purely based on standard javabean and datamodel conventions. Generics became very handy to programmatically find out the type of the nested/joined bean/table and vice versa. That was a good learning path to learn more about Generics in reflection.

During normal work I seldom create parameterized classes. Everything I need is already available
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

None of the above, we're still fighting to escape Java 1.4!
I am so keen to get there, though.
Angel Taveras
Ranch Hand

Joined: Nov 13, 2008
Posts: 84

Hello everyone,

I just try to use them as much as i can, but most of the time i use the generic classes that are already.

I believe that when the most popular frameworks like Hibernate, Spring and such, expose more generic methods then the people will use them more, i understand that these framework don't use them that much. I understand that they want to preserve backward compatibility or because it's too much work and it's better to provide new functionalities.

Well in either case sometimes the developers need to be pushed forward with more generic examples, more information and a few patterns to correctly use and promote the usage of generics.

Yes David, it's still hard to get rid of the influence of Java 1.4...

I agree. Here's the link:
subject: informal poll: how are you using generics?
It's not a secret anymore!