News for hackers. Stuff that matters.
Re:Java's records, Lombok's data, and Kotlin's data classes by TJSomething on Friday May 07, 2021 @03:40PM (#27080073)
In traditional Java, you're probably using Jackson for your JSON. You can achieve those sorts of results by specifying the classes and type tags in annotations on an abstract Either class to use Jackson's polymorphic serialization feature.
Re:Java's records, Lombok's data, and Kotlin's data classes by balefrost on Friday May 07, 2021 @04:04PM (#27080299)
The point of sealed classes is that you have a known number of possible representations. So you can have `when` blocks that exhaustively check all possibilities. Having an open class hierarchy would not work for that purpose.
Re:Java's records, Lombok's data, and Kotlin's data classes by __jem on Friday May 07, 2021 @09:17PM (#27082722)
this technique works with sealed classes, i’ve done it before. it throws a runtime exception if it can’t identify the discriminant.