在将列表用作参数时出现不兼容类型错误。

huangapple go评论70阅读模式
英文:

Getting an Incompatible types error when using List as a parameter

问题

我有下面的这个方法,调用createInternalUserSearchClauses时会引发错误:error: incompatible types: UserSearchClause cannot be converted to List<UserSearchClause>

createInternalUserSearchClauses的签名明确接受一个List<UserSearchClause>作为参数,而and显然是一个List<UserSearchClause>,那么为什么会出现这个错误?

public UsersPage find(List<UserSearchClause> and) {
  List<UserSearchClause> internalAnd = createInternalUserSearchClauses(and);
}
private UserSearchClause createInternalUserSearchClauses(List<UserSearchClause> userSearchClauses) {}
英文:

I have this method below which causes the error error: incompatible types: UserSearchClause cannot be converted to List&lt;UserSearchClause&gt; when trying to call createInternalUserSearchClauses.

The signature for createInternalUserSearchClauses clearly takes a List&lt;UserSearchClause&gt; as the param and and is clearly a List&lt;UserSearchClause&gt; so why am I getting this error?

public UsersPage find(List&lt;UserSearchClause&gt; and) {
  List&lt;UserSearchClause&gt; internalAnd = createInternalUserSearchClauses(and);
}
private UserSearchClause createInternalUserSearchClauses(List&lt;UserSearchClause&gt; userSearchClauses) {}

答案1

得分: 3

createInternalUserSearchClauses的返回类型不是列表。

英文:

The return type of createInternalUserSearchClauses is not a list.

huangapple
  • 本文由 发表于 2020年10月27日 05:14:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64545081.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定