美文网首页
Override方法参数覆写

Override方法参数覆写

作者: 兴浩 | 来源:发表于2018-07-05 14:48 被阅读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();
        }
    }
    

    相关文章

      网友评论

          本文标题:Override方法参数覆写

          本文链接:https://www.haomeiwen.com/subject/yjdpuftx.html