Which null-check is preferable?
Optional.ofNullable(port).ifPresent(settings::setPort);
or
if (port != null) {
settings.
It is dependent on several factors when to use this.
If port is a property within the class, probably using Optional is a bit overkill. (and don't useOptionals as property as they are not serializbie)
I think Optionals are great when for example writing a library.
public Optional getPort()
Is much more descriptive for other developers then
// Returns null if not set
public Integer getPort()