3 回答

TA贡献1775条经验 获得超8个赞
class ShapeBuilder { ... public Shape build() { ....}class CircleBuilder extends ShapeBuilder{ ... @Override public Circle build() { ....}
如果返回类型是引用类型,则返回类型可能因重写方法而异。返回类型可替换性的概念支持协变量返回,即返回类型对子类型的专门化。
具有返回类型R1的方法声明D1是返回类型R2的另一个方法D2的返回类型替换,当且仅当以下条件保持:
如果R1为空,则R2为空。
如果R1是原语类型,则R2与R1相同。
如果R1是一个参考类型,那么:
R1是R2的子类型,也可以通过未经检查的转换将R1转换为R2的子类型(第5.1.9节),或
R1=\x{e76f}

TA贡献1951条经验 获得超3个赞

TA贡献1815条经验 获得超6个赞
package com.sandbox;public class Sandbox { private static class Parent { public ParentReturnType run() { return new ParentReturnType(); } } private static class ParentReturnType { } private static class Child extends Parent { @Override public ChildReturnType run() { return new ChildReturnType(); } } private static class ChildReturnType extends ParentReturnType { }}
添加回答
举报