Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List.of Bug #361

Open
LongerFase opened this issue Dec 29, 2024 · 1 comment
Open

List.of Bug #361

LongerFase opened this issue Dec 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@LongerFase
Copy link

var l=List.of("a","b ");
l.add("rr");

No error hint when coding,but compile error,because List.of return immutableCollection.

@shivam71
Copy link
Member

shivam71 commented Jan 3, 2025

Thanks @LongerFase for noticing this !
You are right that no hint is provided as of now , though this fails only at runtime and not at compile time .
If you check the Java Docs for the List interface it mentions that an UnsupportedOperationException shall be thrown in case one tries to modify an Unmodifiable List. Try the following code :-

var l=List.of("a","b ");
try{
       l.add("rr");
  }catch(UnsupportedOperationException e){
      System.out.println("Caught UnsupportedOperationException ");
  }

This code shall run without any errors .

@Achal1607 Achal1607 added Not-an-issue This cannot be fixed in the Java VS Code extension enhancement New feature or request and removed Not-an-issue This cannot be fixed in the Java VS Code extension labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants