How can I pass a generic type to a method, when I don’t know the type?
public static class ExecContext<E> {
public void doSomething(E e) {
System.out.println(e);
}
}
public static void exec(ExecContext<?> ctx) {
String s = new String("saoj");
ctx.doSomething(s); // <============== COMPILE ERROR
}
should do it.
Edit:
This should do it… a slight change to how you are doing it though: