Guava からの使用に関する良い例をここで読みました。ImmutableSet
完全を期すために、例をここに報告します。
public static final ImmutableSet<String> COLOR_NAMES = ImmutableSet.of(
"red",
"orange",
"yellow",
"green",
"blue",
"purple");
class Foo {
Set<Bar> bars;
Foo(Set<Bar> bars) {
this.bars = ImmutableSet.copyOf(bars); // defensive copy!
}
}
問題は、Java 列挙型を使用して同じ結果を得ることができるかということです。
PS:この質問は私の心に混乱をもたらしました!