Skip to content

Instantly share code, notes, and snippets.

@whoiskai
Last active May 2, 2020 09:28
Show Gist options
  • Save whoiskai/ba7a15689d49b290368fd7341dc3ea86 to your computer and use it in GitHub Desktop.
Save whoiskai/ba7a15689d49b290368fd7341dc3ea86 to your computer and use it in GitHub Desktop.
public final class Box {
private final ArrayList<String> fruits;
public Box(ArrayList<String> fruits) {
this.fruits = fruits.clone();
}
public Box addFruit(String fruit) {
final newBox = new Box(this.fruits.clone());
newBox.fruits.add(fruit);
return newBox;
}
public ArrayList<String> getFruits() {
return this.fruits.clone();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment