3 ms·
I would often use static factory methods as well (next to the other patterns given in the JEP itself), but it breaks the usual convention of using new, so it ad
by BlackFly 3y ago
I would often use static factory methods as well (next to the other patterns given in the JEP itself), but it breaks the usual convention of using new, so it adds a bit of cognitive load to learning an API where you expect to be able to use new, nope that's private, so you try build(), construct(), etc. before finally reading the documents to figure out what the name of the static method is, oh it's initialize().
Constructors in java should enforce class invariants in my opinion. Otherwise we should just have data only record initializers like the new record classes have. I expect a constructor for BigPositiveInteger to never be able to construct a negative integer.