This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Question regarding Generics class of Comparable Type.  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am implementing a binary research tree class which impelments the Map interface:


I am not sure how to procceed though, as i am getting an eroor of  "Bound mismatch".
Declaration:


I tried various alterations, but i am always getting the error:
Any help is appreciated!
 
Marshal
Posts: 61723
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you simply have a K, that can apply to any type. You could add something like a List, which is a bad idea because Lists are mutable and you want immutable objectas as the “K” for a Map. But if you put a List in the Map, it doesn't implement Comparable, so that won't work. You want to assure the compiler that you will only put Comparable objects into the tree, so change its declaration toBy the way, a Comparable object may not implement Comparable to itself. So it might Comparable to its superclass, which you have to allow for. The usual declaration for Comparable is
Foo<T extends Comparable<? super T>>
The second type parameter in a Map is usually V not T.
 
Lampros Marantos
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply and the welcoming!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!