I have classes as below.
public interface ITest <T>
{
public Set<T> methodHere();
}
public class test1 implements ITest<String>
{
Set<String> methodHere(){
return // Set of String
}
}
public class test2 implements ITest<Integer>
{
Set<Integer> methodHere(){
return // Set of Integer
}
}
public class ITestFactory {
public static ITest getInstance(int type) {
if(type == 1) return new test1();
else if(type == 2) return new test2();
}
}
public class TestUser {
public doSomething(int type) {
ITest t = ITestFactory.getInstance(type);
if(type == 1) Set<Integer> i = t.methodHere();
else if(type == 2) Set<String> s = t.methodHere();
...
}
}
There is a warning in the factory class that ITest is used as raw type. What modification should I do to get rid of it?
The TestUser code looks ugly. Am I missing something very basic? I don’t want to use Set<?>
Thanks
Nayn
You can return a
ITest<?>to get rid of the warning but probably you want a more strongly type aproach: