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
You can try using a mapping function:
Optional oa = func2().map(v -> (A) v);
Note that you don't really need to put the (A) cast there, but it makes it a little clearer what's going on.