Answer the question
In order to leave comments, you need to log in
How to cast parameterized types on 'Unchecked assignment'?
How to properly type cast in the following function:
public static <T> Dao<T> getDao(Class<T> cl){
for(Dao dao : daoList){
if (cl == dao.getParameterizedClass())
return dao;
}
return null;
}
return dao
word dao
is highlighted and a warning appears Unchecked assignment: 'dao.Dao' to 'dao.Dao<T>
. public abstract class DaoFactory {
private static final List<Dao<?>> daoList = Arrays.asList(
new DaoImpl<>(Person.class)
);
public static <T> Dao<T> getDao(Class<T> cl){
for(Dao dao : daoList){
if (cl == dao.getParameterizedClass())
return dao;
}
return null;
}
}
Dao
:public interface Dao<T> {
Class<T> getParameterizedClass();
}
public class DaoImpl<T> implements Dao<T> {
private Class<T> parameterizedClass;
DaoImpl(Class<T> cl){
this.parameterizedClass = cl;
}
@Override
public Class<T> getParameterizedClass() {
return parameterizedClass;
}
}
Dao<T>
, but just Dao
. Is there another way to resolve the warning?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question