类型中的方法func(List< Object>)不适用于参数(List< String>) [英] The method func(List<Object>) in the type is not applicable for the arguments (List<String>)

查看:191
本文介绍了类型中的方法func(List< Object>)不适用于参数(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){
}

错误:



b 类型不适用于参数(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&lt; Object&gt;)不适用于参数(List&lt; String&gt;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆