I've a nullable field where I want to perform operation, if not null. return null otherwise. I can write it in plain Java as
return (myfield != null)? myfield.getData() :null;
How can I write the same code in one line with Optional
Something like below. Below code is not a correct code, just want to ask the correct version of it
return Optional.ofNullable(myfield).map(Functionas.identity().getData()).orElse(null);