I’m quite new to both Java and Kotlin (I’ve got C# background) and I’ve learned of a Java concept of Value-based Classes that is realized in some standard Java Class Library types (i.e.
java.time.ZonedDateTime). I believe this is something roughly similar in purpose to C#'s structs and can be used to model small domain types.
Now Kotlin’s data classes with all-val props seem to perfectly fit all the value-based class requirements but one: instantiation via factory methods instead of constructors. The factory method approach allows some optimization where popular instances of a value-based classes can be cached and re-used (correct me if I’m wrong), and this also justifies the other requirement about value-based equality as opposed to reference-based equality. So how do I achieve that with a data class in Kotlin (private ctors + factory methods)?