Remix.run Logo
BlindEyeHalo 3 days ago

Crazy that it took this long to allow parameter validation and transformation before calling super in the constructor.

That was something that always bothered me because it felt so counterintuitive.

delusional 3 days ago | parent | next [-]

Especially because you were always able to bypass it by declaring a `static` function and calling that as part of the parameters to `super`:

public Foo(int x) { super(validate(x)); }

validate would run before super, even though super was technically the first statement in the constructor, and the compiler was happy.

mystifyingpoi 3 days ago | parent [-]

This is such a funny workaround, I like that. But it doesn't matter in any library or your own code, since factory methods are much better (simply because they have names).

PaulHoule 3 days ago | parent | prev | next [-]

I've been programming in Java since before JDK 1.0 and that was one misfeature that bothered me then but that I've long since learned to work around.

extraduder_ire 2 days ago | parent | prev [-]

Wasn't that possible since java 22?

cesarb 2 days ago | parent [-]

> Wasn't that possible since java 22?

From what I've seen, most people only care about the LTS versions of Java. Which means that after Java 21 LTS comes Java 25 LTS. The same happens with Ubuntu (after 22.04 LTS comes 24.04 LTS).