Say I've an interface "Generic" -
public interface Generic<T> {
public T echo(T input);
public List<String> hello();
}
And an implementation class say GenericImpl
with any trivial implementation. Now, when I create an instance of Generic
and invoke hello
, it returns me a List
and not a List<String>
-
Generic g1 = new GenericImpl();
for (String msg : g1.hello()) { // Gives compilation error :
// Type mismatch, cannot convert from element type Object to String
...
Even in eclipse, when I hover on g1.hello
, it shows me the return type as List
and not List<String>
.
This does not happen if I use a normal interface (without generic <T>
). Any suggestions on how to make it work / why does it happen ?