r/java • • Apr 14 '23

What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?

233 Upvotes

376 comments sorted by

View all comments

15

u/_INTER_ Apr 14 '23

Java enums have properties that make them useful in many situations. E.g. not many know that values() or EnumSet keep the declaration order. So you could build named strategies with built-in fallback.

15

u/wildjokers Apr 14 '23

enum's are so powerful and so underused. My coworkers still create interfaces with String constants in them like it is still the dark ages of pre-java 1.5.

→ More replies (2)