2
我正在尝试编写以下代码,其中C
是B
的子类。而getValue方法仅在C
中可用,而不在B
中。但是Eclipse是显示错误在此声明:可选映射类型转换为子类对象
Optional.ofNullable(A).map(A::getB).map(C::getValue);
如果是正常情况下,我们将强制类型转换,写像((C)a.getB()).getValue()
。我如何根据Optional
编写相同的?
我不得不做地图(C.class :: cast) – Sandeep