Han*_*ein 3 java compiler-errors set
当我尝试运行此代码时:
Set<Set<Integer>> s1 = Set.of(Set.of(), Set.of(1));
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
The method of() is undefined for the type Set
The method of(int) is undefined for the type Set
Run Code Online (Sandbox Code Playgroud)
我正在使用 Java 8。出了什么问题?:/
这些方法是在 Java SE 9 中引入的。请参阅@since
API 文档的源代码中的 。您需要升级到当前版本的 Java 或使用其他版本,例如new HashSet<>(Arrays.asList(fred, jim, sheila))
.