generic type binary search tree in java -


i want implement generic type binary search tree. declarations follow:

public btnode<t> {}  public class binarytree<t extends comparable<t>> {}  public class binarysearchtree <t extends comparable<t>> extends binarytree<t> {} 

now have written class called entry , want store instances of class in binarysearchtree.

public class entry implements comparable{ private string firstname, lastname, address, phonenumber;  public entry(string fname, string lname, string address, string phonenum) {     this.firstname = fname;     this.lastname = lname;     this.address = address;     this.phonenumber = phonenum; }  public int compareto(object arg0) {     // todo auto-generated method stub     return 0; } } 

but when declare binarysearchtree<entry> bst, there compile error saying:

"bound mismatch : type entry not valid substitute bounded parameter > of type binarysearchtree"

i still quite new generic type in java. can me solve problem? thanks

your entry class needs implement comparable<entry> instead of raw comparable, raw comparable doesn't match comparable<t>.

public class entry implements comparable<entry> { ... } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -