Last active
August 29, 2015 14:15
-
-
Save vincenthauser/417331e1228bd8ea1bf4 to your computer and use it in GitHub Desktop.
Immutable list
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
// Immutable -- returns an unmodifiable List instead | |
public class SafeStates { | |
private final String[] states = new String[] { "Alabama", "Alaska", ... }; | |
private final List statesAsList | |
= new AbstractList() { | |
public Object get(int n) { | |
return states[n]; | |
} | |
public int size() { | |
return states.length; | |
} | |
}; | |
public List getStates() { | |
return statesAsList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment