Skip to content
Advertisement

Tag: nullable

How to deal with warning ‘unsafe null type convertion’ when using java.lang.Optional

I would like to offer some accessors to a value-container (that is a java.lang.Map under the hood). When implementing accessors like this … ‘ofNullable’ is marked with ‘unsafe null type convertion’. Why is this? The parameter ofNullable is not marked as @NonNull. Is it, because empty() or of() is used and of() is checking for NonNull? Is this a Eclipse-bug,

How to return when an optional is empty?

I love that optionals are in the Java standard library now. But there is one basic problem that I keep running into that I haven’t figured out how to solve in the best way (easiest to read and understand, prettiest, shortest): How to return from a method when an optional is empty? I am looking for a general solution that

Advertisement