public Message setMsg() {
Message message = null;
if (send != null || receive != null) {
message = new Message();
if (receive != null) {
message.setReceive(receive);
}
if (send != null) {
message.setSend(send);
}
}
return message;
}
How can I use Optionals in this case instead of this nested if statement?
final Messageandif-else if-elseto get clean and comprehensible code.receiveandsend, map them toOptionalsof their kind, and reduce them to an optional message.nulls? so why check?)