I have a snippet code for instantiation of a generic type as following:
public class GenericMessageMapper<I ,X>
{
public X xFromI(I imf)
{
// do thing by imf argument
Class<X> clazz = (Class<X>)((ParameterizedType)
this.getClass()
.getGenericSuperclass())
.getActualTypeArguments()[1];
X x = clazz.newInstance();
}
}
Above code worked fine but MyEclipse
show a warning on the code(a yellow under line on preparing clazz
variable line) by this message :Type safety: Unchecked cast from Type to Class<X>
I temporary add following annotation in above of xFromI
method:
@SuppressWarnings("unchecked")
What is reason of this warning and what is solution?