For EnumSet, the set denotes presence of absence of a value by literally using a long integer type, and flipping the bits to represent presence or absence
Wow, Java has bitmasks? What a revolutionary feature. If only Rust had that. /s
Wow, Java has bitmasks? What a revolutionary feature. If only Rust had that. /s
The real trick is not the bitmasks, but being able to know at compile time exactly how many instances are ever going to be created (and thus, how many bits the bitmask needs).
That is the powerful part because we can skip an entire class of validation checks -- that is the performance benefit that Rust can't get, as they chose to enumerate their types rather than their instances of the types.
It took me a while to understand that the author of the message about how cool Java is doesn't understand the difference between an enums, sum types and bitmask at all.
It's actually scary how many upvotes his comment received.
In fact, abstraction over bitwise operations is useful and convenient, but it simply has to be zero-cost.
View all comments
Show parent comment
4
u/sird0rius Oct 07 '25
Wow, Java has bitmasks? What a revolutionary feature. If only Rust had that. /s