I encountered a strange error related to Java using Intellij Idea.
So there is such interface :
<T> void save(T aEntity, DbTransaction dbTransaction, Class<T> clazz);
<T> void save(Collection<T> aEntities, DbTransaction dbTransaction, Class<T> clazz);
When I try to compile the next code :
@SuppressWarnings("unchecked")
@Override
public void save(Collection<T> aEntities, DbTransaction aDbTransaction) {
baseDao.save(aEntities, aDbTransaction, getClass((T) aEntities.toArray()[0]));
}
I receive the next compilation error :
reference to save is ambiguous, both method <T>save(T,DbEntityHelper.DbTransaction,java.lang.Class<T>) in xzc.dao.IBaseDao and method <T>save(java.util.Collection<T>,DbEntityHelper.DbTransaction,java.lang.Class<T>) in xzc.dao.IBaseDao match
Do you have any ideas ? Thanks for help in advance.
You have two types called T
and it can't assume they are the same. T
could be Collection<T>
in the second method or it could be T
in the first.
You can use
baseDao.<T>save(....
or
baseDao.<Collection<T>>save(....
to make it clear which one it should be. Making them the T
same name doesn't help the compiler and may just be confusing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With