HunterShaw
HunterShaw

Reputation: 23

How do i get access to getters for Object o

My question is how do i gain access to my getters for the object o. It is an instance of BankTransaction but when i try to for example use o.getSender() I recieve an error.

@Override
public boolean equals(Object o) {
    if (this instanceof BankTransaction && o instanceof BankTransaction) {
        return true;
    } else {
        return false;
    }
    
}

Upvotes: 1

Views: 46

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201487

You have the first part down. Just add a cast if o is of the right type.

if (o instanceof BankTransaction) {
    BankTransaction bt = (BankTransaction) o;
    // ...
}

Upvotes: 2

Related Questions