[英]Collection : Undefined k,v in Map
i am learning about collection from this site 我正在学习从这个网站收集
Where the guy gave the example 那家伙举了那个例子
import java.util.HashMap;
import java.util.Map;
public class MapTester {
public static void main(String[] args) {
// keys are Strings
// objects are also Strings
Map<String, String> map = new HashMap<>();
fillData(map);
// write to command line
map.forEach((k, v) -> System.out.printf("%s %s%n", k, v));
// add and remove from the map
map.put("iPhone", "Created by Apple");
map.remove("Android");
// write again to command line
map.forEach((k, v) -> System.out.printf("%s %s%n", k, v));
}
private static void fillData(Map<String, String> map) {
map.put("Android", "Mobile");
map.put("Eclipse IDE", "Java");
map.put("Eclipse RCP", "Java");
map.put("Git", "Version control system");
}
}
although in above program i can understand that k and v variable are undefined or not present locally. 虽然在上面的程序中,我可以理解k和v变量是未定义的或不在本地存在。
map.forEach((k, v) -> System.out.printf("%s %s%n", k, v));
and facing the issue with same line. 并面对同一行的问题。
Please help me learning the collections. 请帮我学习收藏。
Correct the project properties Java Compiler : 更正项目属性Java编译器 :
Doesn't work: 不起作用:
Works: 作品:
It is working fine on my system. 它在我的系统上工作正常。 Can you check are you using JDK8?
你能检查一下你使用的是JDK8吗? Lamdas support introduced in JAVA 8. You can test java version by using
java --version
. 在JAVA 8中引入了Lamdas支持。您可以使用
java --version
测试java版本。
Answer of this question 回答这个问题
You need to be using 4.4 (Luna) to get Java 8 support. 您需要使用4.4(Luna)来获得Java 8支持。
Might be useful for someone who checked it later. 对于稍后检查过的人可能会有用。
Thanks @greg-449 谢谢@ greg-449
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.