I have the following methods:
public T fromJson( Reader jsonData, Class clazz ) {
return fromJson( jsonData, (Type)clazz );
}
public <
The problem is the definition of the second method:
public T fromJson( Reader jsonData, Type clazz ) {
There is no way for the compiler to tell what type T
might have. You must return Object
here because you can't use Type
(Type
doesn't support generics).
This leads to a cast (T)
in the first method which will cause a warning. To get rid of that warning, you have two options:
Tell the compiler the type. Use this (odd) syntax:
this.fromJson( jsonData, (Type)clazz );
Note that you need the this
here because
alone is illegal syntax.
Use the annotation @SuppressWarnings("unchecked")
.