从Java 1.6 Collection Framework文档:
不支持任何修改操作(例如
add,remove和clear)的集合称为不可修改.[...]另外保证Collection对象中的任何更改都不可见的集合称为不可变.
第二个标准让我感到困惑.鉴于第一个集合是不可修改的,并假设原始集合引用已被丢弃,第二行中引用的更改是什么?它是指集合中保存的元素的变化,即元素的状态?
第二个问题:
对于一个不可变的集合,如何提供额外的guarentees指定?如果一个线程更新了集合中元素的状态,那么在不可变集合的线程中,状态中的那些更新是不可见的,这对于不变性是否足够?
对于一个不可变的集合,如何提供额外的guarentees指定?
由于catalina.sh中的默认"java.endorsed.dirs"选项,因此无法使用java 9启动基于tomcat的应用程序.
-Djava.endorsed.dirs=/usr/local/share/tomcat/endorsed is not supported. Endorsed standards and standalone APIs in modular form will be supported via the concept of upgradeable modules.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)
有没有解决这个问题?
我正在执行下面的代码片段
System.out.println(List.of(1, 2).getClass());
System.out.println(List.of(1, 2, 3).getClass());
Run Code Online (Sandbox Code Playgroud)
这段代码的输出是;
class java.util.ImmutableCollections$List2
class java.util.ImmutableCollections$ListN
Run Code Online (Sandbox Code Playgroud)
我期待java.util.ImmutableCollections$List3作为第二个语句的输出,因为有一个of()方法需要三个参数,为什么java创建ImmutableCollections$ListN但不是ImmutableCollections$List3?
编辑:这是Java-9问题.在List接口中总共有11个重载的()方法,每个方法从0到10采用可变数量的参数,第11个采用varargs来处理N列表.所以我期待前10个重载方法的List0到List10实现,但它返回带有三个参数的ListN.是的,这是实施细节,但只是想了解更多相关信息.