trying to learn java generic feature but while using it i am getting a warning and unable to understand how i can solve it,though the program in itself is running fine.
i have created a class with following signature
public class MyClass<T> {
public T demo(String string,Class<T> type){
// some work
}
}
now in my other class i am declaring instance of this class as follow
private MyClass myClass;
and than i am trying to call this method from some places like
(ClassB)myClass.demo("hello",ClassB.class);
(ClassC)myClass.demo("hello",ClassC.class);
The program is working fine but i am finding this warning in eclipse.
Type safety: The method demo(String, Class) belongs to the raw type MyClass. References to generic
type MyClass<T> should be parameterized
can any one help me to understand how i can handle this warning?
update
i am using spring to inject myClass instance so can't use new operator here
private MyClass<int> myClass;when declaring the instance.