What are some things in the class library you wish more people knew about or used?

3 years ago by JackbyDev to c/java

module index

I'm curious if there are things in the standard class library that you find useful but not widely used.

load all comments
pohart 7 points 3 years ago

Optional! I was reluctant at first because of the nullibility, but it's so useful.

I'm not sure this is what you were going for. I think most people know about optional and are skeptical because it's not a fix for nullability.

path: 0 319768, hotness: undefined, score: 7, children: 7
BitPirate 3 points 3 years ago

Don't forget its subtypes. OptionalInt, OptionalDouble etc. This avoids auto(un)boxing.

path: 0 319768 371335, hotness: undefined, score: 3, children: 1
pohart 1 point 3 years ago

Oh wow that's great. I didn't know about those at all.

path: 0 319768 371335 376298, hotness: undefined, score: 1, children: 0
JackbyDev 2 points 3 years ago

I didn't have a specific goal, but yeah I do wish more people used Optional.

My one "gripe" with Optional (and I use it lightly) is that they mean for it to only be used as a return type instead of anywhere something can be optional. It can still be used as that though, they just don't recommend it.

path: 0 319768 383497, hotness: undefined, score: 2, children: 4
pohart 1 point 3 years ago

IMHO it should be used for parameters, as long as there is more than one optional parameter. If rather all non nullable parameters though, which is usually doable.

path: 0 319768 383497 384840, hotness: undefined, score: 1, children: 3
java
java

@programming.dev

login for more options
2059
259
34

For discussing Java, the JVM, languages that run on the JVM, and other related technologies.

go to feed...