2 ms·
I really wish the JDK devs would start using constructors again. I understand why factory methods exist but everything these days is of/from/newInstance/somethi
by vips7L 3mo ago
I really wish the JDK devs would start using constructors again. I understand why factory methods exist but everything these days is of/from/newInstance/something else. Dart/Scala/Kotlin have all really solved this with language features and construction is uniform. For example in Dart they have factory constructors: https://dart.dev/language/constructors#factory-constructors https://dart.dev/language/constructors#factory-constructors
- vips7L 3mo agoand for Kotlin/Scala you can use some cheeky operator overloading via companion objects. sealed Interface A { class B: A class C: A companion object { operator fun invoke(s: String) = when (s) { "B" -> B() "C" -> C() } } } val a = A("B")