类型中的方法func(List< Object>)不适用于参数(List< String>) [英] The method func(List<Object>) in the type is not applicable for the arguments (List<String>)
问题描述
我已经尝试过这两段代码,但我得到两个错误。
下面附件都是我和我得到的两个错误。
示例1
static List< String> list = new ArrayList< String>();
public static void main(String [] args){
func(list);
}
private static void func(List< Object> lst){
}
错误:
方法func(List< Object>类型不适用于参数(List< String>)
示例2
static List< Object> list = new ArrayList< Object>();
public static void main(String [] args){
func(list);
}
private static void func(List< String> lst){
}
错误:
类型不适用于参数(List< Object>)
该方法不适用,因为 String
是对象
,但 List< String&
不是列表<对象>
。
I have tried both these pieces of code but I am getting errors for both. Attached below are both pieces and both errors that I am getting. I would appreciate any insight as to why this is happening.
Example 1
static List<String> list = new ArrayList<String>();
public static void main(String[] args) {
func(list);
}
private static void func(List<Object> lst) {
}
Error:
The method func(List<Object>) in the type is not applicable for the arguments (List<String>)
Example 2
static List<Object> list = new ArrayList<Object>();
public static void main(String[] args) {
func(list);
}
private static void func(List<String> lst) {
}
Error:
The method func(List<String>) in the type is not applicable for the arguments (List<Object>)
The method is not applicable because String
is an Object
but List<String>
is not a List<Object>
.
这篇关于类型中的方法func(List< Object>)不适用于参数(List< String>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!