Search code examples
javaextendsinference

How do you implement inference with extensions <java>


I was trying to figure out how to do simple implementations and I thought, what if the interface extends to another interface? so for example,

public interface A{
    public void a();
}

public interface B{
    public void b();
}

public interface C extends B, A {
    public void c();
}

If I was to implement interface C on another class what do I have to do? I tried this from reading other threads:

public class Example<E extends B&A> implements C{
    public void c(){
    }
}

Which doesn't seem to be right.


Solution

  • Whats wrong with ... simply implementing all interfaces?

    public class Example implements C {
      @Override 
      public void a(){ }
      @Override 
      public void b(){ }
      @Override 
      public void c(){ }
    }
    

    In other words: what do you think to gain from making Example a generic type in the first place?!

    Meaning: if there is a deeper problem that I don't see - you should consider updating your question and explain what you intend to do (to avoid solving a xy problem here). If there is no deeper problem, go with the most simple solution (like the one shown above).