Last active
May 2, 2020 09:28
-
-
Save whoiskai/ba7a15689d49b290368fd7341dc3ea86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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