Questions tagged [unmodifiable]
67 questions
1
vote
7 answers
How to declare that method is returning Collections.unmodifiableMap
I'm returning an unmodifiable map from a method. How do I make sure that any code that tries to modify the returned map will get a compile time error, as opposed to a run time error?
My class:
public class Foo
{
private final Map…

Boundless
- 2,444
- 2
- 25
- 40
0
votes
1 answer
Java 11 handle unmodifiable map
I have a class to process some files which is uploaded zipped.
And a method to unzip and fill a HashMap and convert to an Collection.unmodifiableMap.
public class MyClass extends HttpServlet {
...
private Map rnaseqfiles = new…

Aureliano Guedes
- 767
- 6
- 22
0
votes
1 answer
Can we use both ADFS and Azure AD token in the same Spring boot project?
I am working in a project where we are authenticating any REST API requests from UI or anywhere else using ADFS STS tokens. There are some direct calls from UI with ADFS STS token in header for authentication/authorization and there are some…

errorx
- 1
- 1
0
votes
5 answers
How to merge two unmodifiable Sets in Java?
How to merge two unmodifiable static final sets?
public static final Set ORG_SUBSCRIBER_ALLOWED_NUMBER_CD = Set.of(COMPANY_GST, GOVERNMENT_BODY_GST);
public static final Set INDIVIDUAL_SUBSCRIBER_ALLOWED_NUMBER_CD = Set.of(BUSINESS_PAN,…

Thirumal
- 8,280
- 11
- 53
- 103
0
votes
4 answers
Java - convert unmodifiable sets in a map(key, set) to modifaible
I implemented a function which return Map> , when I call this function it return the sets with type Unmodifiable.
I need to do some operations to this sets, how to convert them to modifiable sets in best practice? Otherwise I got…

AlaaKhalil
- 21
- 1
- 6
0
votes
2 answers
How to make a specialization of Map unmodifiable?
I'm currently refreshing my Java knowledge with an mid-sized coding example. I have a data structure Map, and initialize it typically with new LinkedHashMap<>() to preserve insertion order. I use this very often in my code, and I…

Andi
- 888
- 2
- 10
- 24
0
votes
3 answers
Defects of Immutable collections of Guava?
I am not sure the defects of Immutable collections I understand is correct, so I list them in this answer. Hope someone corrects me here.
a): Comparing to Collections.unmodifiableXXX(), ImmutableXXX.copyOf() loses the source collection feature. For…

卢声远 Shengyuan Lu
- 31,208
- 22
- 85
- 130
0
votes
1 answer
How to set UnmodifiableRandomAccessList to Set
There is an Oauth2Authentication object that contains user-authority. When I want to get its authority and set it in authority of User object like this:
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication)…

reza ramezani matin
- 1,384
- 2
- 18
- 41
0
votes
1 answer
Adding element from unmodifiable list to map
I'm not sure if I'm trying to do something stupid here, but I cannot quite find any fitting information on this matter.
I'm getting a List via Collections.unmodifiableList(MyList) from a remote location.
I then want to add the received Elements into…

Radioo
- 422
- 5
- 18
0
votes
1 answer
Collections.unmodifiableCollection and Collections.unmodifiableSet
Suppose I have the following Set
Set fruits = new HashSet();
fruits.add("Apple")
fruits.add("Grapes")
fruits.add("Orange")
If I wanted to create a defensive copy, so that if the original list is modified, the copy doesn't reflect…
user10287394
0
votes
1 answer
A library with a java unmodifiable list implementation and a method like createAndAdd?
I would like to do something like:
final unmodifiableList1 = staticMethodForUnmodifiableList(1,2,3,4);
final unmodifiableList2 = unmodifiableList1.createAndAdd(5);
System.out.println(unmodifiableList1); // prints 1, 2, 3,…

henry86
- 129
- 1
- 8
0
votes
1 answer
How to make mutable fields of a Java Bean immutable at run time using reflection
I am getting some Java objects from a library which have mutable map objects as fields. I need a way to make those object fields read only at run time by wrapping the map objects in Collections.unmodifiableMap() method. I have tried the below…

Fullstack Guy
- 16,368
- 3
- 29
- 44
0
votes
1 answer
How to create readonly collection in fastutil?
In standard library we have methods like Collections#unmodifiableCollection()
Can't find the same for types collections in fastutil. Please hint!

Dims
- 47,675
- 117
- 331
- 600
0
votes
1 answer
Expression Must Be Modifiable Value (C)
Quick question:
#include
int main(void) {
int divisor, counter, binary, counter2;
int digit0, digit1, digit2, digit3;
float decimal;
printf("Decimal\t\tBinary\n");
for (counter = 0; counter <= 15; counter++) {
…

Sean
- 2,890
- 8
- 36
- 78
0
votes
1 answer
Is updating reference of unmodifiableMap thread safe
I have a map (let's call it original map), which is initially null. During service deployment and every hour after that, I need to refresh this map or basically reassing it.
Here is how I do it. In the refresh, I create a new map, and return an…

Arnav Sengupta
- 423
- 1
- 7
- 19