I have a custom class called Card
public class Card implements Serializable, Comparable<Card>{
private static final long serialVersionUID = 100L;
private Rank rank;
private Suit suit;
public Card(Rank rank, Suit suit){
this.rank = rank;
this.suit = suit;
}
public enum Rank{
TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11);
private final int value;
Rank(int value){
this.value = value;
}
}
public enum Suit{
CLUBS, DIAMONDS, HEARTS, SPADES;
public static Suit getSuit(){
Random rand = new Random();
return values()[rand.nextInt(values().length)];
}
}
To check if they're the same I'm doing this:
Card smth = new Card(Card.Rank.ACE,Card.Suit.CLUBS);
Card smth1 = new Card(Card.Rank.ACE,Card.Suit.CLUBS);
System.out.println(smth.equals(smth1));
but its always giving me false
and I have no idea why is that, I've also tried putting them in an ArrayList
and checking with contains()
but the output is the same.