Direction (String name) { return new Direction() { @Override int asInt() { for (int i = 0; i < ourConcreteDirections.size(); i++) { if (ourConcreteDirections.get(i) == this) return i; } throw new InternalError("Explicit direction absent in ourConcreteDirections: " + name); } @Override public String toString() { return name; } }; }