I have created generic interface.
public interface Abc<T> {
void validatePojo(T input);
}
Following two class are implemation of above interface.
1)-----------------------------------------------
public class Hello implements Abc<Pojo1> {
@Override
public void validatePojo(Pojo1 input) {
// some code
}
}
2)-----------------------------------------------
public class Hi implements Abc<Pojo2> {
@Override
public void validatePojo(Pojo2 input) {
// some code
}
}
Now when I tried to create object of Abc,
T input = getInput(someInput); // getInput return either Pojo1 or Pojo2
Abc abc = someFactory(someInput); //someFactory(someInput) will return either `new Hello()`
^ //or `new Hi()` based on `someInput`
|
+-------------------------------//warning
abc.validate(input);
public Abc<?> someFactory(final int input) {
return input == 1 ? new Hi() : new Hello();
}
public T getInput(final int input) {
return input == 1 ? new Pojo1() : new Pojo2();
}
I am getting waring Abc is a raw type. References to generic type Abc<T> should be parameterized
.
How can I reslove this warning?
I looked on the internet found following but it is not very useful.
- One way that I found was to use
@SuppressWarnings
. - Declare variable like
Abc<Pojo1> abc
orAbc<Pojo2> abc
, I can not do this as whehther to use Pojo1 or Pojo2 is totally depend on input.(I don't want to write logic of factory method here)
Is there any other way to reslove it?