Java unchecked method invocation
Posted
by
Sam
on Stack Overflow
See other posts from Stack Overflow
or by Sam
Published on 2014-08-25T08:53:21Z
Indexed on
2014/08/25
10:20 UTC
Read the original article
Hit count: 353
java
I'm trying to setup a multithreaded application using SQLite4java, and everything is working fine. However, according to the getting started tutorial I am meant to create an object of type "object" and in order to return a value of null (due to use of generic types).
Here is the suggested code:
queue.execute(new SQLiteJob<Object>() {
protected Object job(SQLiteConnection connection) throws SQLiteException {
// this method is called from database thread and passed the connection
connection.exec(...);
return null;
}
});
The following example code I created produces the same error:
error:
test.java:9: warning: [unchecked] unchecked method invocation: <T,J>execute(J) in com.almworks.sqlite4java.SQLiteQueue is applied to (query<java.lang.Integer>)
queue.execute(new query<Integer>());
test.java:
import com.almworks.sqlite4java.*;
import java.util.ArrayList;
import java.io.File;
class test{
public static void main(String[] args){
File f = new File("file.db");
SQLiteQueue queue = new SQLiteQueue(f);
queue.execute(new query<Integer>());
}
}
query.java:
import com.almworks.sqlite4java.SQLiteException;
import com.almworks.sqlite4java.SQLiteJob;
import com.almworks.sqlite4java.SQLiteConnection;
import com.almworks.sqlite4java.SQLiteStatement;
import java.util.ArrayList;
class query<T> extends SQLiteJob{
protected ArrayList<Integer> job(SQLiteConnection connection) throws SQLiteException{
ArrayList<Integer> ints = new ArrayList<Integer>();
//DB Stuff
return ints;
}
}
I have read a lot about how this particular message appears when people fail to specify a type for an ArrayList. However, I am not attempting to cast the object or do anything with it. It is merely a mechanism implemented by the library developers in order to return a null. I do not believe this to be an issue relating directly to the library, which is why I'm asking this on StackOverflow.
I believe it all comes down to my lack of experience with generic types. I've already spent a few hours on this and don't feel like I am getting anywhere.
How do I stop the warning?
© Stack Overflow or respective owner