hi guys, I am practising with Trees The code below is belong to a class called BinaryTree please take a look at the bold portion, i did a Customer casting. As a result, this method is not generic and robust anymore because the whole BinaryTree class can only be used on Customer class but not other classes. My searchkey is Comparable type which is used to uniquely identify the class.
what should i do so that I no need to use (Customer) casting??
I tried using tmpn1.getClass() tmpn1.getItem()).setKey((Comparable) (v1+v2)); but it doesn;t work.
BTW, your code still wouldn't work for any KeyedItem, but just for those that use Integers as keys, but I guess you are aware of that?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: May 25, 2005
hi, yup the key item is in integer form
I have a customer class with name, address and a superclass KeyedItem with Comparable searchKey
I have 2 customers record (account id=20 and account id = 10)
my concern is to 1. add the account id together -> 30 2. copy the first customer record (account id=20) to account id=30
tt's the reason y i cast customer becoz I want to get the object of customer account id 20, change the search key to 30 only while retaining the original values of address and name.
but i find that my code is not robust
Joined: Jul 11, 2001
Why is the search key a Comparable instead of an Integer? Can you change the KeyedItem class?