Java Scala包装泛型匿名类
我正试图通过使用scala闭包使这段代码变得更好:Java Scala包装泛型匿名类,java,scala,closures,Java,Scala,Closures,我正试图通过使用scala闭包使这段代码变得更好: SQLiteQueue queue = new SQLiteQueue(databaseFile); queue.start(); queue.execute(new SQLiteJob<Object>() { protected Object job(SQLiteConnection connection) throws SQLiteException { connection.exec(.
SQLiteQueue queue = new SQLiteQueue(databaseFile);
queue.start();
queue.execute(new SQLiteJob<Object>() {
protected Object job(SQLiteConnection connection) throws SQLiteException {
connection.exec(...);
return null;
}
});
所以我可以这样使用它:
queue.execute { conn => do something with conn}
但是我在super.execute(job)
错误:推断的类型参数[Nothing,com.almworks.sqlite4java.SQLiteJob[T]]
不符合方法execute的类型参数界限[T,J调用execute时指定类型参数:
super.execute[T, SQLiteJob[T]](job)
调用execute时指定类型参数:
super.execute[T, SQLiteJob[T]](job)
你能试一下super.execute[T,SQLiteJob[T]](job)
?@RégisJean-Gilles奏效了!想把它作为一个答案吗?尽管我回答错了,但我还是坚持我的建议:在def something={…}中使用=
是一个很好的做法
当您打算返回除单元以外的内容时
@Damian:当然。我避免立即添加它,因为我没有测试它。您可以尝试使用super.execute[T,SQLiteJob[T]](作业)
?@RégisJean-Gilles奏效了!想把它作为一个答案吗?尽管我的答案是错误的,但我还是坚持我的建议:当你打算返回除单元
以外的东西时,最好使用=
中的=
。@Damian:当然。我避免立即添加它,因为我没有测试它。
super.execute[T, SQLiteJob[T]](job)