If I need plain string in Groovy, does using double-quoted literals make any influence on performance?
For instance:
def plainString = 'Custom string'
def gString = "Custom string"
In my understanding, plain String
should be faster because during runtime there are no searches for specific characters and substitutions.
From the Groovy Language Specification:
Double quoted strings are plain
java.lang.String
if there’s no interpolated expression, but aregroovy.lang.GString
instances if interpolation is present.
Therefore, feel free to use double quotes or single quotes: they will result in the same type of object. The difference will be when you have a $
in the double-quoted string. But by then, we are talking semantics, not performance.