So, I have two common interfaces.
The first interface is implemented as follows.
public interface First<E> { void method(E e) } public class FirstImpl implements First<String> { void method(String s) { System.out.println(s); } } public class FirstImpl2 implements First<Double> { void method(Double d) { System.out.println(d); } }
I need a second interface (the second interface is shown below) is a generic type that allows you to use only the classes that are used to implement the first interface, in our case String and Double . Is there any clean way to do this, something like
public interface Second <E, ? extends First<E>> { void method(E e); } public class SecondImpl <E> implements Second <E, ? extends First<E>> { void method(E e) { System.out.println(e); } }
therefore, in the second generic E will only String and Double and all classes that are used to implement First<E> correspond?
source share