Multiple uses of "this" keyword in Java
Posted
by
frodosamoa
on Stack Overflow
See other posts from Stack Overflow
or by frodosamoa
Published on 2011-02-17T06:02:11Z
Indexed on
2011/02/17
7:25 UTC
Read the original article
Hit count: 142
So, I have this. It compares two card decks and if they are the same the result is true.
public boolean equals ( Object obj ) {
boolean result = true;
for (int i = 0; i < 52; i++) {
if (this.cardAt(i) = this2.cardlist(i)) {
result = true;
} else {
result = false;
}
}
}
I would like to be able to compare two random card decks, if you will. But I don't know how to compare two different ones using "this . I simply wrote "this2" to replace another instance of "this". What could I do to replace this "this2" to still be able to compare two card decks?
© Stack Overflow or respective owner