Is there an efficient way to perform upcasting while using an Optional object. Here is a sample code:
class A{}
class B extends A{}
B func(){
//do somet
The cleanest way to do this I think would be Optional a = func2().flatMap(Optional::of) or Optional a = func2().map(Function.identity()) because both do not require casting and only use existing functionality.