0
votes

I'm trying to call one of the overloaded query() methods in Spring 3.0's JdbcTemplate class in Scala...

val args: Array[Object] = new Array[Object](1)
args(0) = id
val results: List[MyObj] = jdbcTemplate.query(SQL_STRING, args, new MyJdbcStore.MyObjRowMapper)

...and I get a stack trace that says, "overloaded method value query with alternatives." (The MyObjRowMapper in the above code snippet is a class, defined in MyJdbcStore's companion object, that extends Spring's RowMapper interface.) The "alternatives" are the three versions of query() that have these parameters respectively:

java.lang.String, Array[java.lang.Object], org.springframework.jdbc.core.ResultSetExtractor
java.lang.String, org.springframework.jdbc.core.PreparedStatementSetter, org.springframework.jdbc.core.ResultSet
org.springframework.jdbc.core.PreparedStatementCreator, org.springframework.jdbc.core.PreparedStatementSetter, org.springframework.jdbc.core.ResultSetExtractor

Even though I've explictly defined the return type of the results variable, why can't the compiler determine which query method to call?

1
Are you sure MyJdbcStore.MyObjRowMapper is an instance of type ResultSetExtract ?paradigmatic
No, as I mentioned in the post, MyObjRowMapper is a RowMapper. I'm trying to call the version of query() that takes a String, an array of Objects, and a RowMapper--and returns a list.Jeffrey Chung
Overloaded methods are not chosen by result type.Alexey Romanov
To quote Martin Odersky: "Overloaded methods need an explicit result type because the result type is one of the things that's used to determine whether a method alternative is applicable or not." scala-programming-language.1934581.n4.nabble.com/…Jeffrey Chung
Did you import java.util.List or is this a Scala List?Alexey Romanov

1 Answers

2
votes

The query method you are invoking returns an object of type java.util.List[T]. Apparently you are expecting a Scala List.