不存在类型变量 T 的实例,因此 List<T> 符合 Integer
No instance(s) of type variable(s) T exist so that List<T> conforms to Integer
在下面的代码中:
return new HashSet<>(namedParameterJdbcTemplate.query(
SOME_SQL_QUERY_STRING,
parametersMap,
(resultSet, rowNum) -> resultSet.getBigDecimal("GETID")
));
我在 (resultSet, rowNum) -> resultSet.getBigDecimal("GETID"))
下看到一条红线和以下错误:No instance(s) of type variable(s) T exist so that List<T> conforms to Integer
。有人可以帮我说说为什么会这样吗?
根本问题是(根据代码)推断出 "query" 方法的不同(不需要的)重载版本,并且作为第三个参数给出的 lambda(函数)不适合此版本的"query".
解决此问题的一种方法是 "force" 通过提供类型参数来实现您想要的查询功能:
return new HashSet<>(namedParameterJdbcTemplate.<BigDecimal>query( ...
add an explicit casting to your method call
就我而言,我有
<T> Map<String, T> getMap(@NotNull String rootPath, @NotNull Class<T> type)
我用过它
LinkedHashMap<String,String> x = xmlRegestryFile.getMap("path/to/map/of/string", String.class)
但它失败了并给了我那个错误,所以我通过添加转换来克服这个错误
x = (LinkedHashMap<String, String>) xmlRegestryFile.getMap("my/path", String.class)
在下面的代码中:
return new HashSet<>(namedParameterJdbcTemplate.query(
SOME_SQL_QUERY_STRING,
parametersMap,
(resultSet, rowNum) -> resultSet.getBigDecimal("GETID")
));
我在 (resultSet, rowNum) -> resultSet.getBigDecimal("GETID"))
下看到一条红线和以下错误:No instance(s) of type variable(s) T exist so that List<T> conforms to Integer
。有人可以帮我说说为什么会这样吗?
根本问题是(根据代码)推断出 "query" 方法的不同(不需要的)重载版本,并且作为第三个参数给出的 lambda(函数)不适合此版本的"query".
解决此问题的一种方法是 "force" 通过提供类型参数来实现您想要的查询功能:
return new HashSet<>(namedParameterJdbcTemplate.<BigDecimal>query( ...
add an explicit casting to your method call
就我而言,我有
<T> Map<String, T> getMap(@NotNull String rootPath, @NotNull Class<T> type)
我用过它
LinkedHashMap<String,String> x = xmlRegestryFile.getMap("path/to/map/of/string", String.class)
但它失败了并给了我那个错误,所以我通过添加转换来克服这个错误
x = (LinkedHashMap<String, String>) xmlRegestryFile.getMap("my/path", String.class)