Mohamed Taboubi
Mohamed Taboubi

Reputation: 7011

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 ? will we have to implements 4 methods or 8 methods?

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 ?

Now If a class implements AddressCrud in this case ? will we have to implements 4 methods or 8 methods?

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

Upvotes: 3

Views: 71

Answers (2)

VienNguyen
VienNguyen

Reputation: 12

The tag @Override is meaningless in your case. BTW, the implementation classes for AddressCrud will implement for 4 methods.

Upvotes: 0

Lior Chaga
Lior Chaga

Reputation: 1480

You don't need to declare any method in AddressCrud. It's sufficient to just extend 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>. In either case, you will have only 4 methods to implement

Upvotes: 1

Related Questions