I am new to Java. Can someone explain to me what is the difference between using lambda and method here?
Method equals()
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Book)) {
return false;
}
Book book = (Book) o;
if (!author.equals(book.author)) {
return false;
}
return title.equals(book.title);
}
Lambda equals()
public Function<Object, Boolean> equals = (Object o) -> {
if (this == o) {
return true;
}
if (!(o instanceof Book)) {
return false;
}
Book book = (Book) o;
if (!author.equals(book.author)) {
return false;
}
return title.equals(book.title);
};
Method hashCode()
@Override
public int hashCode() {
return 31 * author.hashCode() + title.hashCode();
}
Lamba hashCode()
public Supplier<Integer> hashCode = () -> 31 * author.hashCode() + title.hashCode();
I wanted to use Lambda instead of method for equals and hashCode.
Is it OK?