I always thought that two interfaces with the same method cannot be inherited by one class, as stated in many so questions.
Java jre 7, jdk 1.7
But this code here is working.
Example:
Interfaces:
public interface IObject
{
public Object create(Object object) throws ExceptionInherit;
}
public interface IGeneric<T>
{
public T create(T t) throws ExceptionSuper;
}
Implementing class:
public class Test implements IGeneric<Object>, IObject
{
@Override
public Object create(final Object object) throws ExceptionInherit
{
return object;
}
}
Don't those two method declarations have the same body?
Exceptions:
The exceptions are just additive to this construct making it more complex.
public class ExceptionSuper extends Exception {}
public class ExceptionInherit extends ExceptionSuper {}
It works without any thrown exceptions too.
Further: If both methods interfaces throw different inheriting exceptions i could cast UserLogic
to any of the two interfaces and retrieve a different subset of the exceptions!
Why is this working?
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);
{
// print arg
}
}