泛型编译错误
android项目使用ormlite出现错误 我在这段代码上遇到编译错误:
public class DatabaseModel {
private Dao<Object, Integer> mDao = null;
private DatabaseHelper mHelper;
private Class<?> mClass;
public DatabaseModel(DatabaseHelper h, Class<?> c) {
mHelper = h;
mClass = c;
try {
mDao = mHelper.getDao(mClass);
} catch (SQLException e) {
Debug.e("Can't get dao", e.getStackTrace());
throw new RuntimeException(e);
}
}
on line 25 mDao = mHelper.getDao(mClass);
Error: type parameters of <D>D cannot be determined; no unique maximal
instance exists for type variable D with upper bounds
com.j256.ormlite.dao.Dao<java.lang.Object,java.lang.Integer>,
com.j256.ormlite.dao.Dao<capture#296 of ?,?>
但是当我尝试使用 eclipse 构建项目时,它工作正常
该错误看起来类似 这个问题。
不知道是Idea的这个bug还是javac的这个bug。
我的配置: IntelliJ IDEA 11.0.2 构建#IC-111.277 建于 2012 年 1 月 1 日。 JDK:1.6.0_29 VM:Java HotSpot(TM) 64 位服务器 VM 供应商:苹果公司
Error appears in android project using ormlite
I get compilation error on this code:
public class DatabaseModel {
private Dao<Object, Integer> mDao = null;
private DatabaseHelper mHelper;
private Class<?> mClass;
public DatabaseModel(DatabaseHelper h, Class<?> c) {
mHelper = h;
mClass = c;
try {
mDao = mHelper.getDao(mClass);
} catch (SQLException e) {
Debug.e("Can't get dao", e.getStackTrace());
throw new RuntimeException(e);
}
}
on line 25 mDao = mHelper.getDao(mClass);
Error: type parameters of <D>D cannot be determined; no unique maximal
instance exists for type variable D with upper bounds
com.j256.ormlite.dao.Dao<java.lang.Object,java.lang.Integer>,
com.j256.ormlite.dao.Dao<capture#296 of ?,?>
But when i tries to build project using eclipse it works fine
The error looks similar to this SO question.
I don't know whether this bug of Idea or javac.
My configuration:
IntelliJ IDEA 11.0.2
Build #IC-111.277
Built on 1 Февраль 2012 г.
JDK: 1.6.0_29
VM: Java HotSpot(TM) 64-Bit Server VM
Vendor: Apple Inc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 eclipse 中没有收到此错误,但我可以明白为什么您会看到问题。
mdao
定义为Dao
但您正在调用getDao(mClass)
,其中mclass
是类
。对象!=?在通用土地上。您可以将整个类转变为泛型类型。像下面这样的东西会起作用。
那应该有效。
I'm not getting this error in eclipse but I can see why you would see a problem.
mdao
is defined asDao<Object, Integer>
but you are callinggetDao(mClass)
wheremclass
is aClass<?>
. Object != ? in generic land.You could turn your entire class into a generic type. Something like the following would work.
That should work.
就我而言,我可以使用
getDataDao()
而不是getDao()
来规避该问题。In my case, I could circumvent the problem by using
getDataDao()
instead ofgetDao()
.