Creating a Union of multiple sets which is affected by changes in original sets

StackOverflow https://stackoverflow.com/questions/23317632

  •  10-07-2023
  •  | 
  •  

Domanda

For an assignment I have to write a method which combines a number of sets into one set and returns it.

This is easy enough, but the interface specifies that the returned set should be backed by the group of sets, that is to say that making a change to one of the subsets affects the overset.

By creating a Set and using .addAll() on each of the subsets, will this result in the desired behavior? The Javadoc doesn't say if it's a shallow or deep copy.

È stato utile?

Soluzione

For anyone else who finds this question, the answer is no, changing the subsets does not affect the superset if you've used .addAll() from the standard library.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top