!7 //!include #1010605 // WeakHashMap2 sclass Symbol { S text; bool test; *() {} *(S *text, bool *test) {} // weird signature to prevent accidental calling public int hashCode() { ret main.hashCode(text); } toString { ret text; } public bool equals(O o) { if (!test) ret this == o; ret o instanceof Symbol && eq(text, o/Symbol.text); } } static new WeakHashMap symbolMap; static Symbol symbol(S s) { if (s == null) null; synchronized(symbolMap) { Symbol test = Symbol(s, true); //WeakHashMap2.Entry e = symbolMap.getEntry(test); //Symbol sym = e == null ? null : e.get(); O e = call(symbolMap, 'getEntry, test); Symbol sym = cast callOpt(e, 'get); if (sym == null) symbolMap.put(sym = Symbol(s, false), Bool.TRUE); ret sym; } } p { Symbol a = symbol("a"); Symbol a2 = symbol("a"); assertEquals("a", str(a)); assertEquals("a", str(a2)); assertIdentical(a, a2); Symbol b = symbol("b"); assertEquals("b", str(b)); }