Created
March 8, 2015 19:10
-
-
Save Locke/3ad00fafe6237baef66f to your computer and use it in GitHub Desktop.
java - static initialization block
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
/* | |
original question: https://twitter.com/SchwarzeLocke/status/574632128270442497 | |
How could I achieve this #scala code easily in #java? | |
> val a = Set("a", "b") | |
> val b = Set("c", "d") | |
> val c = (a ++ b + "x" + "y").toArray | |
Many thanks to @Szernex and @Waldteufel | |
*/ | |
class Foo { | |
public static final List<String> a = Arrays.asList("a", "b"); | |
public static final List<String> b = Arrays.asList("c", "d"); | |
private static final List<String> tmp; | |
public static final String[] c; | |
static { | |
tmp = new LinkedList<String>(); | |
tmp.addAll(a); | |
tmp.addAll(b); | |
tmp.add("x"); | |
tmp.add("y"); | |
c = tmp.toArray(new String[tmp.size()]); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment