Skip to content

Instantly share code, notes, and snippets.

@Locke
Created March 8, 2015 19:10
Show Gist options
  • Save Locke/3ad00fafe6237baef66f to your computer and use it in GitHub Desktop.
Save Locke/3ad00fafe6237baef66f to your computer and use it in GitHub Desktop.
java - static initialization block
/*
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