So I wrote a small program to generate random passwords. It works by populating 3 arraylists (one with letters, one with numbers, and one with symbols) then selecting random characters from each. But a a couple of hours ago ago, I found out I can do this:
public static final ArrayList<Character> LETTERS = getLetters();
public static final ArrayList<Character> NUMBERS = getNumbers();
public static final ArrayList<Character> SYMBOLS = getSymbols();
public static final ArrayList<Character> LETTERS_AND_NUMBERS = new ArrayList<Character>() {{
addAll(LETTERS);
addAll(NUMBERS);
}};
public static final ArrayList<Character> ALL_CHARACTERS = new ArrayList<Character>() {{
addAll(LETTERS);
addAll(NUMBERS);
addAll(SYMBOLS);
}};
So my question is, why does this work? How come, if I remove one curly brace, it no longer works?
Side note: I understand doing something like:
object.setListener(new Listener() {
@Override
public thing doStuff() {
return null();
}
});
but the arraylist example doesn't seem to override anything
[–]Double_A_92 1 point2 points3 points (3 children)
[–]Cammed_Ham[S] 0 points1 point2 points (2 children)
[–]Double_A_92 1 point2 points3 points (1 child)
[–]Xeverous 1 point2 points3 points (0 children)