A Ruby symbol is an immutable string object which gets indexed in a symbol table for singe-reference re-use (hence the very inventive nomenclature!).
In Java, all String
objects are immutable, and all of them are indexed in the (inventively named) symbol table for re-use by the JVM (as long as they are referenced and live).
So, in Java, a String
("my_symbol"
) is the equivalent of a Ruby symbol (:my_symbol
).
To get something equivalent to a Ruby 'my string'
(non-immutable), you'd have to go to more complex Java classes (new StringBuilder("my string")
, etc.). Or, if you have Groovy loaded the JVM, it overlays a similar mutable concept with GString.