public class Card
{
long id;
String name;
Rank rank;
long price;
public Card(long id, String name, Rank rank)
{
this.id = id;
this.name = name;
this.rank = rank;
this.price = 0;
}
public String toString()
{
return "id: " + this.id + "\n" + "name: " + this.name + "\n" + "rank: " + this.rank + "\n" + "price: " + this.price;
}
public boolean equals(Card card)
{
if (this.id == card.id)
{
if (this.name.equals(card.name))
{
if (this.rank == card.rank)
{
return true;
}
}
}
return false;
}
public int hashCode()
{
return id.hashCode() + name.hashCode() + rank.hashCode();
}
}
I wrote a class Card with id, name, price and rank which is enum Rank.
I'm trying to override equals and hashCode. The two cards compared should be considered equal only if the id, name, and rank are the same.
I get "long cannot be dereferenced". I can't just use id itself cus it's long not int.