Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Need clarification on Object.equals.

Reply
Thread Tools

Need clarification on Object.equals.

 
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Wed, 19 Dec 2012 15:40:54 +0000, lipska the kat
<(E-Mail Removed)> wrote:

[snip]

>Well you still don't get it do you
>I don't defend insulting behavior but sometimes flesh and blood can
>stand just so much, lets try again. One question at a time.


Why not relax and enjoy the nice USENET?

>You said
>
>"My point is that while newbies do have a "allowed to post
>stupid questions" card"
>
>Who 'allows' them to post stupid questions.


Freedom of speech.

>Do you understand the question
>
>It's a very simple question, really it is. who is it ?
>I really do want to know.


However, freedom of speech does not require the recipient to
listen or to take it seriously. It also allows the recipient to
reply.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/19/2012 12:39 PM, Patricia Shanahan wrote:
> On 12/19/2012 9:06 AM, Arne Vajhøj wrote:
>> On 12/19/2012 11:43 AM, Lars Enderin wrote:
>>> 2012-12-19 17:22, Arne Vajhøj skrev:
>>>> On 12/19/2012 11:13 AM, FredK wrote:
>>>>> On Tuesday, December 18, 2012 10:56:19 AM UTC-8, Peter Duniho wrote:
>>>>>> On Tue, 18 Dec 2012 04:48:16 -0800, Roedy Green wrote:
>>>>>>>> Node a = new Gate();
>>>>>>>> Monitor b = new Monitor();
>>>>>>>> System.out.println(a.equals(b)); // --> prints 'true'
>>>>>>> Gate or one of its superclasses is implementing equals.
>>>>>> And doing it incorrectly, I'd say.
>>>>>
>>>>> Why would you think it was done incorrectly?
>>>>> For most classes, a.equals(b) is not the same as a==b.
>>>>> Think about string:
>>>>> string a = "abc");
>>>>> string b = new string(a);
>>>>> Clearly a==b is false, but a.equals(b) is true.
>>>>>
>>>>> Usually the equals() method returns true if the internal state of both
>>>>> objects is the same.
>>>>
>>>> It is rather unusual to have objects of different classes considered
>>>> equals.
>>>>
>>>> Your example is different.
>>>
>>> Both Gate and Monitor were extensions of AbstractSet, and empty, which
>>> eventually led to Set#containsAll, and thus equals, returning true.

>>
>> Yes. We know that now. And the problem was solved by not
>> extending that.
>>
>> But if the class should continue to extend from
>> that it should probably have overridden equals again
>> with an implementation that did use instanceof to test
>> for type (it could have called super.equals after that
>> if appropriate).

>
> AbstractSet implements Set, so all its subclasses also implement Set.
>
> That means they are bound by the Set contract for .equals, which treats
> all classes that implement Set the same way. There might be a
> performance advantage to overriding AbstractSet's .equals in some cases,
> but its result would have to be preserved.


If the Set interface specify the behavior of equals, then testing for
type is not valid.

Testing for type may only make sense on domain classes and not
for container classes at all.

> The right solution is, of course, the action the OP is already taking -
> don't extend AbstractSet unless you really are implementing a Set, and
> intend to follow the Set contract.


Yes.

Arne


 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      12-19-2012
On 12/19/2012 11:58 AM, lipska the kat wrote:
> If 'Joshua' has a problem with me let him be the one to speak.


If I feel I have nothing to add to a discourse, I won't say anything. I
also have this nasty habit of ignoring insults or responding to them (or
pretty much anything else) with humor.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
FredK
Guest
Posts: n/a
 
      12-19-2012
On Wednesday, December 19, 2012 8:22:28 AM UTC-8, Arne Vajhøj wrote:
> On 12/19/2012 11:13 AM, FredK wrote: > On Tuesday, December 18, 2012 10:56:19 AM UTC-8, Peter Duniho wrote: >> On Tue, 18 Dec 2012 04:48:16 -0800, Roedy Green wrote: >>>> Node a = new Gate(); >>>> Monitor b = new Monitor(); >>>> System.out.println(a.equals(b)); // --> prints 'true' >>> Gate orone of its superclasses is implementing equals. >>And doing it incorrectly, I'd say. > > Why would you think it was done incorrectly? > For most classes, a.equals(b) is not the same as a==b. > Think about string: > string a = "abc"); > string b = new string(a); > Clearly a==b is false, but a.equals(b) is true. > > Usually the equals() method returns true if the internal state of both objects is the same. It is rather unusual to have objects of different classes considered equals. Your example is different. Arne


Which points out that the real issue is that you must define what you want equals() to mean. There may well be situations where two objects of different classes could be considered to be "equal" ( Consider a Square with side=2, and a (immutable) Rectangle with width=2 and length=2 )
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Wed, 19 Dec 2012 17:27:12 +0000, lipska the kat
<(E-Mail Removed)> wrote:

>On 19/12/12 17:12, Lars Enderin wrote:
>> 2012-12-19 17:51, lipska the kat skrev:
>>> On 19/12/12 15:57, Lars Enderin wrote:

>
>>
>> Why don't you like it when somebody stands up for somebody else? It's
>> not abnormal behaviour. And in this case Arne may have felt that the
>> OP's reply was (also) directed at him. But I am not allowed to answer
>> for Arne, right?

>
>Well in the real world nobody answers for me except me. I stand and fall
>by my own decisions and am quite prepared to take the consequences of my
>actions however harsh those consequences may be.


Not everyone has to do that.

>However we are not in the real world are we. We are in a world where


Yes, we are. The idea that the Net is not part of the real world
is inane.

[snip]

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Wed, 19 Dec 2012 18:49:21 +0000, lipska the kat
<(E-Mail Removed)> wrote:

>On 19/12/12 18:22, Gene Wirchenko wrote:
>> On Wed, 19 Dec 2012 15:40:54 +0000, lipska the kat
>> <(E-Mail Removed)> wrote:

>
>[snip]
>
>> However, freedom of speech does not require the recipient to
>> listen or to take it seriously. It also allows the recipient to
>> reply.

>
>Oh a light in the darkness.
>
>I couldn't agree more the important bit here of course is
>
>It also allows the *recipient* to reply (my accent)
>
>I have no problem with the recipient replying, what I object to is the
>mass rounding on an individual by multiple aggressive responders
>'standing up for' people who I am sure are well able to stand up for
>themselves
>
>THIS is unacceptable and I for one will not tolerate it any longer.


How are you going to do that?

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Wed, 19 Dec 2012 19:05:55 +0000, lipska the kat
<(E-Mail Removed)> wrote:

>On 19/12/12 18:16, Arne Vajhøj wrote:
>> On 12/19/2012 12:50 PM, lipska the kat wrote:
>>> The behaviour of you and you pals is unacceptable to me.

>>
>> Pals?
>>
>>> If I see this behaviour again I will take you to task again.

>>
>> You will just make a fool out of yourself again.

>
>Never worried me before and it won't worry me in the future.
>Unlike you and your rather sad little collection of puffed up self
>important 'friends' I have the courage of my convictions.


It is too bad that so many of these convictions are not working
out very well for you. You have done an excellent job of antagonising
quite a few people here in a very short time.

[snip]

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Wed, 19 Dec 2012 19:16:26 +0000, lipska the kat
<(E-Mail Removed)> wrote:

>On 19/12/12 18:19, Gene Wirchenko wrote:
>> On Wed, 19 Dec 2012 14:36:21 +0000, lipska the kat
>> <(E-Mail Removed)> wrote:
>>
>> [snip]
>>
>>> This is USENET, you don't own it, you don't have the right to tell
>>> people what they can and cannot post, in fact you are just another
>>> faceless whiner among so many faceless whiners.

>>
>> You are presuming to tell him what he can post here. How is it
>> that your statement does not apply to you

>
>Am I, I don't get that at all from my statement. I'm questioning his
>authority to tell others what they can and can't post.


"...you do not have the right to tell..." is doing exactly that.

>English can be a tricky language.
>
>What I will not tolerate however is the 'ganging up' on unsuspecting
>users. I can take it, in fact I find the discourse exhilarating, others
>may be more badly affected.


Why not let them speak for themselves? You seem to think that we
should do that. Try applying it yourself.

>If you think that sort of behaviour is acceptable then I'm afraid you
>are part of the problem.


There was no big deal here until you made one.

>I'm trying to put a name to this behaviour. When I do I'll make it quite
>clear where I stand. (Yet again)


Like a broken record?

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      12-19-2012
lipska the kat wrote:
> Now I'm not normally driven to using bad language but
> What the f**k is wrong with you people.


What the **** is wrong with /you/?

> This is Usenet, not your private little universe.


People gave a perfectly reasonable answer to the question, and "ple..." got
their knickers in a twist.

> I've noticed this a lot in various newsgroups that I have been
> frequenting of late. People who are regular contributors get the idea
> that foo.bar.baz newsgroup is their private domain and anyone who has
> the temerity to post a question that doesn't meet their exacting
> standards get flamed and scolded and told to stop whining.


Maybe the OP should not have whined, then.

> I get told off but I have the skin of a Rhino and none of you silly
> little jibes affect me or my life in any way whatsoever. Not everyone is
> so unaffected.


They weren't "jibes", as you hope to convince us without evidence by the mere
use of the word. They were valid advice.'

> Please think before you flame.


Physician, heal thyself.

> Oh, and by the way, my flames are ALWAYS justified


As any troll would say, your disingenuous smiley-face notwithstanding.

--
Lew
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      12-20-2012
Peter Duniho <(E-Mail Removed)> writes:
>If a person wants to write a private message, to which only that one
>private recipient of the message may reply, then they should send the
>message privately.


This is already the default:

void person( final Object object )
{ final Reply reply = object.message(); }

Now, only »object« will directly get the message,
and only »person« will directly get the reply.

If you want a public message, you might try something like:

void person( final Infrastructure infrastructure, final Object object )
{ final Reply reply = infrastructure.sendPublicly( object, new Message() ); }

>Public messages grant the right of public comment.


void person( final Infrastructure infrastructure, final Object object )
{ final Reply reply = infrastructure.sendPublicly( object, new Message() );
final Comments comments = infrastructure.getPublicComments( reply ); }

»getPublicComments« might block your thread until
infrastructure.getMaxCommentWaitTime() seconds have
passed. See also: »Infrastructure#peekPublicComments«.

I hope that helps you with you project! (If you like
messages, you also might like to have a look at the
programming language Smalltalk.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need clarification on a function declaration wizwx C Programming 9 02-13-2007 03:19 PM
need clarification with import statements Tool69 Python 2 12-15-2006 11:56 AM
Need clarification on 'typedef' keyword Krishna C++ 5 04-01-2005 05:21 PM
Need clarification on asp_wp.exe,aspnet_wp.exe and aspnet_isapi.dll prem ASP .Net 1 11-03-2004 05:32 AM
Need some clarification and/or help with java NIO sockets HDSkiFreak Java 2 05-11-2004 01:48 PM



Advertisments