Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Scala包装泛型匿名类_Java_Scala_Closures - Fatal编程技术网

Java 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(.

我正试图通过使用scala闭包使这段代码变得更好:

  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)