Given the following classes
abstract class SomeAbstractClass
data class DataClass() : SomeAbstractClass()
class NoDataClass() : SomeAbstractClass()
For any instance of SomeAbstractClass
, can I determine whether it is a data class without relying on type checking?
Some background: this seemed the best way of combining inheritance and data classes to me, as suggested in a different answer. Now, within the initializer block of SomeAbstractClass
, I want to throw an exception in case the derived type is not a data class to ensure 'correct' (immutable) implementations of derived types.
Aucun commentaire:
Enregistrer un commentaire