Repository navigation
docs: clarify List.of mutability and mutable array copies - #2940
Open
Shubham-Padkonde wants to merge 1 commit into
Open
Shubham-Padkonde wants to merge 1 commit into
Shubham-Padkonde wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2649.
数组转列表一节以
ArrayList为标题,但其中的List.of()示例返回不可修改的列表,容易让读者误以为它支持增删元素。将标题改为
List,说明List.of()不支持添加、删除或替换元素,也不接受null,并补充复制到ArrayList后进行修改的例子。保留与Arrays.asList()的区别:后者可以替换元素。验证:
javac --release 9)并运行示例检查:确认三种修改操作抛出UnsupportedOperationException、包含null时抛出NullPointerException、Arrays.asList()支持替换,以及可变副本的结果与注释一致。git diff --check通过。行为依据:Java List 的 Unmodifiable Lists 说明。