Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

informal poll: how are you using generics?

 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
subhajit paul
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
TIA
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic