Everything is in order, provided that you take care of any possible synchronization; for example, if there are several threads that can modify the map and / or list.
You might be confused when you modify a key object. This is clearly NOT normal if the modification violates the hash table invariants; eg.
- if it causes a key hash change or
- if it forces the key to give a different result than the other key used in the table.
I ask in terms of OOP design.
I would say that the OO design is neutral on this. You are using a Java interface (i.e. Map ) that does not control values. You do not break encapsulation because the values ββare not in the Map abstraction.
Whether this is a sound design in terms of application depends on the overall design. We cannot judge one way or another without understanding the context.
source share