• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading "Adding Wildcards to Java" paper - a question

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In section 2.2; the paper justifies the need for super-bounded wildcards.

It gives one usecase for super-bounds which is in Comparator objects.

I'm not convinced by this argument. The inheritance tree is only

one level. If it were 4-5 levels deep; then it might make more sense.
In this case; using an implementation of Comparator<Object> is defeating the purpose of generics which is to implement type safe code. Instead I resort to writing code like this:

What do you think?
[ April 25, 2008: Message edited by: Pho Tek ]
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pho Tek:
In this case; using an implementation of Comparator<Object> is defeating the purpose of generics which is to implement type safe code.

In this case yes. Consider another example though:

The thing is, for Comparator<A> and Comparator<Object> you have less values to sort on, but sometimes that's ok.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic