ifndef SymbolAsString sclass symbol_Tester extends MasterSymbol { *(S text) { super(text, true); } } static WeakHashMap symbol_map = newWeakHashMap(); endifndef static Symbol symbol(S s) { ifdef SymbolAsString ret s; endifdef ifndef SymbolAsString if (s == null) null; synchronized(symbol_map) { // This is a trick that works because of how WeakHashMap compares keys. O e = call(symbol_map, 'getEntry, symbol_Tester(s)); MasterSymbol sym = e == null ? null : ((WeakReference) e).get(); if (sym == null) symbol_map.put(sym = new MasterSymbol(s, true), true); ret sym; } endifndef } static Symbol symbol(CharSequence s) { if (s == null) null; ifdef SymbolAsString ret str(s); endifdef ifndef SymbolAsString if (s instanceof Symbol) ret (Symbol) s; if (s instanceof S) ret symbol((S) s); ret symbol(str(s)); endifndef }