简体   繁体   English

interface覆盖其他接口的方法

[英]interface override a method of an other interface

given 特定

   public interface Crud<T> {
        public T get();
        public T add(String json);
        public T update(String json);
        public T delete(String json);
    }

   public interface AddressCrud extends Crud<AddressResponse> {
        public AddressResponse get();
        public AddressResponse add(String json);
        public AddressResponse update(String json);
        public AddressResponse delete(String json);
    }

If a class implements AddressCrud ? 如果一个类实现了AddressCrud? will we have to implements 4 methods or 8 methods? 我们要实现4种方法还是8种方法?

Now if we write : 现在,如果我们写:

   public interface AddressCrud extends Crud<AddressResponse> {
        @Override
        public AddressResponse get();
        @Override
        public AddressResponse add(String json);
        @Override 
        public AddressResponse update(String json);
        @Override
        public AddressResponse delete(String json);
    }

I know @Override is used to override the implementation of a method, but in the case of an interface is the @Override make a sense ? 我知道@Override用于覆盖方法的实现,但是在接口的情况下@Override是否有意义?

Now If a class implements AddressCrud in this case ? 现在如果一个类在这种情况下实现了AddressCrud? will we have to implements 4 methods or 8 methods? 我们要实现4种方法还是8种方法?

update: for your information: I am using a feign clients and I need to declare interface per client .. I have several feign clients ... there are annotation that are different between the interfaces .. this is why I am trying to make a common interface that I called Crud 更新:为了您的信息:我正在使用假装客户端,我需要为每个客户端声明接口..我有几个假装客户端......接口之间有不同的注释..这就是为什么我要创建一个我称之为Crud的常见界面

You don't need to declare any method in AddressCrud . 您不需要在AddressCrud声明任何方法。 It's sufficient to just extend Crud<AddressResponse> . 只需扩展Crud<AddressResponse>就足够了。 Tha't the whole point in generics. 这不是泛型的全部意义。 In fact, you don't need even to declare AddressCrud , you can just have the class implement Crud<AddressResponse> . 实际上,你甚至不需要声明AddressCrud ,你可以让类实现Crud<AddressResponse> In either case, you will have only 4 methods to implement 在任何一种情况下,您只需要实现4种方法

The tag @Override is meaningless in your case. 在您的情况下,标签@Override毫无意义。 BTW, the implementation classes for AddressCrud will implement for 4 methods. 顺便说一下, AddressCrud的实现类将实现4种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM