0

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.

4

1 回答 1

3

来自Groovy 语言规范

java.lang.String如果没有插值表达式,双引号字符串是普通的,但groovy.lang.GString如果存在插值,则为实例。

因此,请随意使用双引号或单引号:它们将产生相同类型的对象。不同之处$在于双引号字符串中有 a 。但到那时,我们谈论的是语义,而不是性能。

于 2017-02-16T16:21:41.130 回答