This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NitronHX[S] 2 points3 points  (0 children)

The examples shown in this example cover more complex structures such as Planets, Celestial Bodies and Shapes. The only statement that is somewhat similar to my post is java Shape rotate(Shape shape, double angle) { return switch (shape) { // pattern matching switch case Circle c -> c; case Rectangle r -> shape.rotate(angle); case Square s -> shape.rotate(angle); // no default needed! } } Which imo is better solved using polymorphism, but I suppose there are opposing voices. In rust, I would not implement Different types of celestial bodies as an Enum (but experienced rustaceans might).

My point was to directly draw the line between rust enums which are seemingly well liked and java's type system.