Override方法参数覆写
2018-07-05 本文已影响8人
兴浩
方法返回值参数可以通过继承的方式覆写
public class BaseEntity {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class SubEntity extends BaseEntity {
private Integer age;
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
public interface BaseInterface {
BaseEntity submit();
}
public interface SubInterface extends BaseInterface {
@Override
SubEntity submit();
}
public class TestInterface {
@Test
public void test1()
{
SubInterface subInterface=new SubInterface()
{
@Override
public SubEntity submit() {
SubEntity entity=new SubEntity();
entity.setName("test");
return entity;
}
};
SubEntity entity=subInterface.submit();
}
}