Marc Berenbach wrote:
> You can't perform that cast in Java, but you can use the hashCode()
> method to get a unique integer representation of the reference.

Java's Object.hashCode() is not guaranteed to be unique:

* It is not required that if two objects are unequal according to the 
equals(java.lang.Object) method, then calling the hashCode method on 
each of the two objects must produce distinct integer results. However, 
the programmer should be aware that producing distinct integer results 
for unequal objects may improve the performance of hashtables.


Regardless, you can still pretend you're using a language that gives you 
a unique representation of each list node.  In C, you could get the 
address of the list node, which would be unique.

-- 
Richard Kasperowski (mailto:[EMAIL PROTECTED])
Tel: 617-576-1552, Fax: 617-576-2441
http://www.altisimo.com/



> 
> -----Original Message-----
> From: Jeff Parker [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, April 17, 2002 10:52 AM
> To: CS 119 (E-mail)
> Subject: [cscie119] 'funny stuff'
> 
> 
>  
> 
>>For the whistle problem, how are we allowed to treat the
>>nodes... can I get an integer value of the node in some 
>>way (ie a hashcode, or the address of).  Or can we only 
>>treat it as a java reference in that here's the value, 
>>you can only compare it and not really do anything else.
>>
>>Marc
> 
> 
> Marc -
>       Can't you always cast a reference?
> 
>               int val = (int)reference;
> 
> If you cannot in Java, pretend you are writing
> in C, where you can.  
> 
> - jeff parker
> 
> 
> 
> 


Reply via email to