You can avoid a warning e.g. with the following code:
public T getObject(Class type){
Object o = getSomeObject();
if (type.isInstance(o)){
return type.cast(o);
} else {
return null;
}
}
while the following code will raise a warning:
public T getObject(){
return (T) getSomeObject();
}