首页 > 其他 > 详细

Type mismatch: cannot convert from element type Object to String 解决办法

时间:2019-08-19 11:39:59      阅读:113      评论:0      收藏:0      [点我收藏+]

首先放上我的源码,看看你的代码是不是我这个类似的。

 1 @Test
 2     void predicateTest() throws Exception {
 3         List<String> languages = Arrays.asList("Java", "Scala", "C++", "Haskell", "Lisp");
 4         System.out.println("Languages which starts with J :");
 5         filter(languages, (str) -> ((String) str).startsWith("J"));
 6         System.out.println("Languages which ends with a ");
 7         filter(languages, (str) -> ((String) str).endsWith("a"));
 8         System.out.println("Print all languages :");
 9         filter(languages, (str) -> true);
10         System.out.println("Print no language : ");
11         filter(languages, (str) -> false);
12         System.out.println("Print language whose length greater than 4:");
13         filter(languages, (str) -> ((String) str).length() > 4);
14     }
15 
16     public static void filter(List names, Predicate condition) {
17         for (String name : names) {
18             if (condition.test(name)) {
19                 System.out.println(name + " ");
20             }
21         }
22     }

存在问题截图

技术分享图片

解决办法

技术分享图片

 

Type mismatch: cannot convert from element type Object to String 解决办法

原文:https://www.cnblogs.com/xzk666/p/11375736.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!