Questions tagged [unmodifiable]

67 questions
8
votes
3 answers

is unmodifiableList thread safe?

i have a list of string(tagList) which need to shared among multiple threads for reading, so i create a unmodifiable version of it and pass it to threads, i m not sure if it's thread safe, since threads only read that list so i guess it should be…
user468587
  • 4,799
  • 24
  • 67
  • 124
7
votes
1 answer

Why is my `unmodifiableList` modifiable?

I want a List whose elements cannot be removed nor added. I thought I'd found the answer with Collections.unmodifiableList in Java 8. I pass my original list and get back a supposedly unmodifiable list. Yet when I delete an element from the…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
7
votes
3 answers

Class that describes a immutable, ordered set

I need some class/interface name that describes an immutable, ordered set (in input order, like LinkedHashSet). I can of course just use the class like this: class Foo { public final Set frozenOrderedSet; public Foo(List input)…
WorldSEnder
  • 4,875
  • 2
  • 28
  • 64
5
votes
2 answers

Ruby equivalent of Java's Collections.unmodifiableList and Collections.unmodifiableMap

Is there a equivalent in the Ruby standard API for Java's Collections.unmodifiableList and Collections.unmodifiableMap?
razenha
  • 7,660
  • 6
  • 37
  • 53
5
votes
4 answers

How do I make a Map unmodifiable?

The java.util.Collections class allows me to make collection instances unmodifiable. The following method protected Map> getCacheData() { return Collections.unmodifiableMap(tableColumnCache); } returns an umodifiable Map,…
My-Name-Is
  • 4,814
  • 10
  • 44
  • 84
4
votes
1 answer

Why does Collections.unmodifiableCollection allow you to change the collection?

Suppose I have to following set: Set fruits = new HashSet() fruits.add("Apple") fruits.add("Grapes") fruits.add("Orange") Set unmodifiableFruits = Collections.unmodifiableSet(new…
user10287394
4
votes
6 answers

How inefficient is passing Collections.unmodifiable* an instance which is already wrapped with Collections.unmodifiable*?

I have bits of piecework being done by different custom (source code unavailable) frameworks which hand back Map instances. Unfortunately, these frameworks are not consistent in their returning Map instances which have been wrapped with…
chaotic3quilibrium
  • 5,661
  • 8
  • 53
  • 86
4
votes
1 answer

Clone/Copy unmodifable list

Is there any other option for me to modify an unmodifiable list apart from manual traversal and putting content into new array? Some developers choose to build APIs this way rather than cloning ..
Tian Na
  • 846
  • 2
  • 15
  • 30
4
votes
4 answers

Unmodifiable List of modifiable objects

Let's say we have got a List> and want to make it completely unmodifiable. Simply passing it to a Collection.unmodifiableList would not suffice because the inner Lists can still be modified. I would go with the following…
user3726374
  • 583
  • 1
  • 4
  • 24
4
votes
3 answers

Concurrent access to unmodifiableMap

@Singleton @LocalBean @Startup @ConcurrencyManagement(ConcurrencyManagementType.BEAN) public class DeliverersHolderSingleton { private volatile Map deliverers; @PostConstruct private void init() { Map
shurik2533
  • 1,770
  • 4
  • 22
  • 41
3
votes
1 answer

Method unmodifiablelist() cannot be applied to given type

I am trying to compile a former co-worker's code but it says that the method unmodifiableList() can not be applied to a given type. The code in Eclipse does not show any error. But it still does not let me compile it. What could be the error?…
Newbie
  • 43
  • 5
3
votes
2 answers

I can't use in GWT Collections.unmodifiableList(List l) to make only readable my List, because isn't serializable, alternative ways?

I'm using GWT-RPC to create an application. At certain point the server return a Collection using Collections.unmodifiableList(List l) to the client. The client give an error: [WARN] Exception while dispatching incoming RPC…
anto150192
  • 539
  • 3
  • 13
3
votes
2 answers

Does an unmodifiable view of TreeMap retain the key ordering?

Suppose I have a TreeMap map. I need to view an unmodifiable version from a getter so I return a Map of return Collections.unmodifiableMap(map);. However, I need it to be returned with the same ordering of keys as it was when…
user2763361
  • 3,789
  • 11
  • 45
  • 81
2
votes
1 answer

Making an object property unchangeable through reassignment but modifiable in JavaScript

class Hero extends Character { constructor (name, race, gender, role, level){ super(name, race, gender, role, level); this.inventory = []; this.experience = { experienceNeeded: 100, experienceObtained: 0 }; …
Zlorak
  • 63
  • 6
2
votes
2 answers

How does Collections.unmodifiableList (Java 8 SE) get modified when making a new ArrayList from it?

I have a getter that returns an unmodifiable list, as such: public List getProductList() { if (productList == null) return new ArrayList<>(); return Collections.unmodifiableList(productList); } I am calling this getter as…
Griford
  • 333
  • 1
  • 4
  • 13