0

I wrote an abstract class for which I am certain that all subclasses will need to override .equals and .hashCode to be useful. The abstract class does not however have the information required to itself override these methods. Is it possible to require the subclasses of the abstract class to override the method?

vexrav
  • 97
  • 3
  • 1
    As an aside: it is pretty complicated to enforce a sound definition of `equals(...)` within sub-classes (especially if someone else might subclass your abstract class, mind that [`equals(...)` should be reflexive by contract](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object))). – Turing85 Jun 13 '19 at 19:22

1 Answers1

2

Yes, you need to make the methods abstract as well, e.g.

abstract boolean equals(Object o);
Turing85
  • 18,217
  • 7
  • 33
  • 58
katamaster818
  • 341
  • 2
  • 12