Java 21 makes me actually like Java again

https://wscp.dev/posts/tech/java-pattern-matching/

45 points · 9 comments · view on lemmy.world

9 Comments

igorlogius@lemmy.world · 28 pts · 3y
[ removed ]
PortugalSpaceMoon@infosec.pub · 10 pts · 3y (5 replies)

I'm not sure I agree that Void is a bottom type. If so, void-functions would never be able to return/terminate. Java's void is probably more of a unit type.

BatmanAoD@programming.dev · 4 pts · 3y (4 replies)

They allude to this later, acknowledging that it's sort of a cross between unit and bottom.

aloso@programming.dev · 4 pts · 3y (3 replies)

No it's not, it is 100% a unit type (except it's not really a type, since you can only use it as return type and nowhere else)

BatmanAoD@programming.dev · 5 pts · 3y (2 replies)

It's not possible to instantiate or assign, which is more like a never type than a unit; and it is not possible to define new types with the same properties, which is also more like bottom than unit. But you're right that it's not actually a true never type since it can't represent function divergence.

I think the truth is just that Java's type system isn't very mathematically disciplined.

aloso@programming.dev · 1 pts · 3y (1 reply)

It's not possible to instantiate or assign, which is more like a never type than a unit

Actually, this is because void is not a type, it is just a keyword, a placeholder used instead of the return type when a function doesn't return anything.

If it were a bottom type, that would mean that a method returning void must diverge, which is simply not true.

Also, if it were a bottom type, it would be possible to write an "unreachable" method

void unreachable(void bottom) {
    return bottom;
}

Even though it couldn't be called, it should be possible to define it, if void was a bottom type. But it is not, because void isn't a bottom type, it's no type at all.

BatmanAoD@programming.dev · 1 pts · 2y

The post has been edited; it looks like someone on reddit made essentially the same point. You're right of course that void isn't a true type in Java, but the post now also discusses Void, which I suppose just shows how void infects the type system despite not being a type.

solrize@lemmy.world · 7 pts · 3y

It's nice that Java has gotten those features but the article is pretty confused about type theory.

TheCee@programming.dev · 5 pts · 3y

It'll probably take Valhalla for me, personally.

SpaceNoodle@lemmy.world · 2 pts · 3y

When did you start liking it?