I always thought that two interfaces with the same method cannot be inherited by the same class, as indicated in many such issues.
Java jre 7, jdk 1.7
But this code works here.
Example:
Interfaces:
public interface IObject { public Object create(Object object) throws ExceptionInherit; } public interface IGeneric<T> { public T create(T t) throws ExceptionSuper; }
Class implementation:
public class Test implements IGeneric<Object>, IObject { @Override public Object create(final Object object) throws ExceptionInherit { return object; } }
Don't these two method declarations have the same body?
Exceptions:
Exceptions are simply additive for this design, which makes it more complex.
public class ExceptionSuper extends Exception {} public class ExceptionInherit extends ExceptionSuper {}
It also works without any exceptions.
In addition: If both method interfaces throw different inheriting exceptions, I can use UserLogic for either of the two interfaces and catch another subset of the exceptions!
Why does it work?
Edit:
The generic implementation is not even necessary: public interface IA { public void print(String arg); } public interface IB { public void print(String arg); } public class Test implements IA, IB { @Override public void print(String arg); {
source share