Created
February 8, 2017 19:59
-
-
Save genderquery/a1985f8b8dd4515b0a884e67b2782c53 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
class Main { | |
public static void main(String[] args) { | |
Household household = new Household(); | |
final List<Person> people = household.getPeople(); | |
// will throw UnsupportedOperationException | |
people.add(new Person("Avery Larsen")); | |
} | |
} | |
class Person { | |
private String name; | |
Person(final String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
} | |
class Household { | |
private List<Person> mPeople; | |
public Household() { | |
mPeople = new ArrayList<>(); | |
} | |
public List<Person> getPeople() { | |
return Collections.unmodifiableList(mPeople); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment