Results 1 to 5 of 5
Thread: Equals
- 06-09-2012, 09:26 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
Equals
hi all,
i was going through the concept of .equals operator which according to me checks the objects content equivality. But when i tried to run my sample code mentioned below
class Const
{
public Const(String n)
{
System.out.println(n);
}
public static void main(String[] args)
{
Const cst = new Const("sam");
Const ts = new Const("sam");
//ts= cst;
if(cst.equals(ts))
{
System.out.println("equal");
}
else
System.out.println("not equal");
}
}
I get the out put as "not equal" which i guess shouldn't be. Can any one help me out here?
Thank you
- 06-09-2012, 09:33 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Equals
You should read some more about the equals( ... ) method and its compadre hashCode(); for one thing: you didn't implement them (according to the code you've shown us).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-09-2012, 09:40 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
Re: Equals
ohh ok thanks
- 06-09-2012, 01:35 PM #4
Re: Equals
50 posts and you still haven't learned how to post code? Or are you just lazy?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-11-2012, 08:12 AM #5
Banned
- Join Date
- Jun 2012
- Location
- Beijing,China
- Posts
- 34
- Rep Power
- 0
Similar Threads
-
using .equals
By droidus in forum New To JavaReplies: 11Last Post: 01-21-2012, 03:33 AM -
c always equals a*b
By imorio in forum New To JavaReplies: 3Last Post: 11-12-2010, 02:32 PM -
== and equals()
By arefeh in forum New To JavaReplies: 13Last Post: 01-05-2010, 04:56 PM -
== is same as .equals()??
By DrMath in forum New To JavaReplies: 1Last Post: 09-30-2009, 04:57 AM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks