I have the following general method in my project that will return a BaseModel object that depends on the specified class:
public <T> T getObjectfromList(Class<T> clazz) {
for (BaseModel model : items) {
if (model.getClass().equals(clazz))
return (T) model;
}
return null;
}
}
Now I get a lint warning on the line return (T) modelbecause it is an uncontrolled selection from BaseModelto T.
To get around this, I added the following link here:
public <T extends BaseModel> T getObjectfromList(Class<T> clazz) {
for (BaseModel model : items) {
if (model.getClass().equals(clazz))
return (T) model;
}
return null;
}
}
However, a lint warning still appears. How can I get around this?
source
share