Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
4.0.9, 4.0.11
-
None
Description
If a method parameter's default value is defined by concatenating a String literal to a String variable, calling the method throws java.lang.NoSuchMethodError.
import groovy.transform.CompileStatic import spock.lang.Specification @CompileStatic // works without CompileStatic class MyClass { String makePlural(String word, String plural = word + "s") { // java.lang.NoSuchMethodError: 'java.lang.String java.lang.String.plus(java.lang.CharSequence)' return plural } } class Test extends Specification { def test() { setup: MyClass myObj = new MyClass() expect: myObj.makePlural("word") == "words" } }
A workaround is to do the concatenation in a GString:
String makePlural(String word, String plural = "${word}s") {
Attachments
Issue Links
- is related to
-
GROOVY-11023 SC: IncompatibleClassChangeError when closure direct-targets extension method
- Closed