About object
Hi
/*********** CODE *************/
public class Test {
private int num;
public Test(int num) { this.num = num; }
public boolean check(Test obj) {
return equals(obj);
}
public static void main(String[] args) {
Test m = new Test(2);
Test n = new Test(2);
System.out.print(m.check(n));
}
}
/*********** CODE *************/
On the code above java print FALSE, but both value of the objects are equals. I know that those 2 object has different address and that's why they are not equals. My question is how can i make them equals???
In Integer class, if we create 2 different obj with same value, they print statement will print TRUE, How they do that?
I try to create generic class of linked list and i need way to see if the given object as type E is equal to one of the object in my linked list. Since i cannot have an access to obj data, i cannot see that each object carrying same data. but my node class can return obj with type E which is on my list.
Thanks
Mani
|