Thanks to visit codestin.com
Credit goes to github.com

Skip to content

warning hints on mutable methods used with immutable collections #8519

@naren2605

Description

@naren2605

Description

it would be good to have hints showing some warning message("mutable method xyz cannot be used on immutable collection") when immutable collections are used with mutable methods.

example:

var immutableList = List.of(10,20);
      immutableList.add(20);
var immutableList = List.of(10,20);
      immutableList.remove(20);
  • below are the methods which ImmutableCollections.AbstractImmutableList has below operations which throws UnsupportedOperationException
          @Override public boolean add(E e) { throw uoe(); }
          @Override public boolean addAll(Collection<? extends E> c) { throw uoe(); }
          @Override public void    clear() { throw uoe(); }
          @Override public boolean remove(Object o) { throw uoe(); }
          @Override public boolean removeAll(Collection<?> c) { throw uoe(); }
          @Override public boolean removeIf(Predicate<? super E> filter) { throw uoe(); }
          @Override public boolean retainAll(Collection<?> c) { throw uoe(); }
    
  • at the moment no hint is shown
  • Image
  • Image

Use case/motivation

No response

Related issues

related issue JVSCE-361

Are you willing to submit a pull request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)hintskind:featureA feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions