Is there a way to require a method to take in a pa...
# announcements
a
Is there a way to require a method to take in a param that is a data class? Is there a way to require a class to have a companion object that implements an interface? I remember seeing the latter somewhere and there were compile time warnings.
s
Is there a way to require a method to take in a param that is a data class?
No. Data classes are not part of any specific type hierarchy of their own. You cannot extend the notion of a data class or specify an interface that represents all data classes.
r
Is there a way to require a class to have a companion object that implements an interface?
No, that doesn't really make any sense.
k
And think about it: why do want a data class? There's nothing inherently special about them.
a
I’ve thought of that. The main reason I’d use this is to imply that classes should have data equality, or perhaps readable toString() output. Data classes don’t guarantee that and you can definitely accomplish that without data classes, but it may still be a nice to have.
k
Nope, that's all just implementation details. Code should not depend on stuff like that.