public final class Symbol extends Object implements Serializable
A Symbol is an inexpensive object that behaves like a singleton -- except that you can create as many as you want. Each Symbol is created with a String, and a unique Symbol is assigned to this String. Any fetches of that String will return the same Symbol.
Symbols cannot be constructed, but must be fetched through the "of" operator.
Symbols are hashable, because they are singletons, so the default hashCode based on Object address should work.
Modifier and Type | Method and Description |
---|---|
String |
getName()
Get the name for a symbol.
|
static Symbol |
of(String name)
Get a unique symbol for name.
|
String |
toString() |
<T> TypedSymbol<T> |
withType(Class<T> type)
Make a typed symbol from this symbol.
|
public static Symbol of(String name)
name
- the name for this symbol during this execution of
the programpublic String getName()
public <T> TypedSymbol<T> withType(Class<T> type)
T
- The type.type
- The type.