Win a copy of Java XML & JSON this week in the XML and Related Technologies 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 62803
203
  • 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!
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!