Re: InetAddress.equals() Anomoly?
From: Pete Loveall (psl_at_ametx.com.NO_SPAM)
Date: 01/08/05
- Next message: David Thielen: "Re: J# support for java 1.3?"
- Previous message: Pete Loveall: "Re: InetAddress.equals() Anomoly?"
- In reply to: Pete Loveall: "Re: InetAddress.equals() Anomoly?"
- Next in thread: Bruno Jouhier [MVP]: "Re: InetAddress.equals() Anomoly?"
- Reply: Bruno Jouhier [MVP]: "Re: InetAddress.equals() Anomoly?"
- Reply: Bruno Jouhier [MVP]: "Re: InetAddress.equals() Anomoly?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 8 Jan 2005 12:37:15 -0600
BTW, the quote in my post was taken from the MSDN Online Library for
InetAddress.equals()
http://msdn.microsoft.com/library/en-us/vjref98/html/java.net.InetAddress007.asp
If J# is to be compatible with Java 1.1.4 (Microsoft's JVM), then areas of
direct incompatibility such as this are bugs in J#. They break working
programs.
It is a major mistake to think that comparing toString() methods (or any
other method, for that matter) for any object provides proper equals()
operation. If the Java API implements equals() for an object, then J# must
use the same general implementation or it risks (as in this case) breaking
working programs with incorrect results.
Your "definition" of two objects being equal has no basis in the Java API.
I refer you to any Java API documenet on Object.equals() for a proper
definition
http://msdn.microsoft.com/library/en-us/vjref98/html/java.lang.Object005.asp
hashCode() must also obey the same rules as equals() with the exception that
two objects with the same hashCode can fail equals(), but two objects that
pass equals() MUST have the same hashCode. In the case of InetAddress, the
hashCode appears to be computed correctly by J#.
Pete Loveall
> "Bruno Jouhier [MVP]" <bjouhier@club-internet.fr> wrote in message
> news:OvNeuxV9EHA.2568@TK2MSFTNGP11.phx.gbl...
>>I don't agree.
>>
>> Two objects are equal if they can be used interchangeably and if they
>> produce the same results when any arbitrary method is applied to them.
>>
>> In your case:
>> dnsaddr.toString() produces firenet.us/12.34.75.101
>> ipaddr.toString() produces grande.rivcom.net/12.34.75.101
>>
>> So, the objects are not equal because they don't produce the same result
>> when you apply toString() to them.
>>
>> If you consider that two InetAddress should be equal as soon as they have
>> the same IP, you take a biased view, you consider that your equals method
>> should take the IP part into account and completely ignore the name side
>> of the INetAddress object. This is wrong. If you start overriding equals
>> to give it "partially equals" semantics, you are going to run into some
>> trouble.
>>
>> So, this is not a bug in the JDK. If you want to use the IP as a hash
>> key, you should use the IP (formatted as a string, or as an integer) as
>> key, you should not use InetAddress because this is a richer object that
>> carries more information than an IP.
>>
>> Bruno.
>
>
- Next message: David Thielen: "Re: J# support for java 1.3?"
- Previous message: Pete Loveall: "Re: InetAddress.equals() Anomoly?"
- In reply to: Pete Loveall: "Re: InetAddress.equals() Anomoly?"
- Next in thread: Bruno Jouhier [MVP]: "Re: InetAddress.equals() Anomoly?"
- Reply: Bruno Jouhier [MVP]: "Re: InetAddress.equals() Anomoly?"
- Reply: Bruno Jouhier [MVP]: "Re: InetAddress.equals() Anomoly?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|