I have a function created where i have used @SuppressWarning("unchecked") at method level and it works as expected but i need to move this @SuppressWarning("unchecked") to only those lines of code where the warning is coming in and not at method level:
public static <T> T marshal(Class<T> cls , String xml){
T res;
if(cls == xml.getClass()){
res=(T) xml;--->Need to use @SuppressWarning("unchecked") before this line
}else{
JAXBContext ct= JAXBContext.newInstance(cls);
Unmarshal marshal=ctx.createUnmarshller();
res=(T)marshal.unmarshal(new StringReader(xml));-->Need to use @SuppressWarning("unchecked") before this line
}
return res;
}
In the above function I have to use @SuppressWarning("unchecked") after if and else because these are the places where warnings are shown.