Groovy / Postgres "No signature of method: java.lang.String.positive()"

The other answer gave you the solution I also would recommend, but it can be good to still know the reason for why this is happening.

Groovy uses operator overloading quite excessively. This means that if you were to write your own class, you can overload the + operator to do many things.

However, there is a difference between using + at the end of a line and at the beginning of a line.

At the end of a line, + is treated as the binary operator append (a + b), but at the start of a line, it is treated as the unary operator positive (+6 is treated as "positive six").

If you were to write this, it would work better:

println "The row Id is: ${row.id}" +
    "The word is: ${row.word}" +
    "The number is: ${row.number}" +
    "The decimal is: ${row.decimal}" +
    "The date-time is: ${row.datetime}"

If you would do this, however, you would get the output on one line, that's because you haven't added new line characters, \n

println "The row Id is: ${row.id}\n" +
    "The word is: ${row.word}\n" +
    "The number is: ${row.number}\n" +
    "The decimal is: ${row.decimal}\n" +
    "The date-time is: ${row.datetime}"

And now things are starting to look uglier, which is why Groovy's multi-line String functionality can come in handy, as shown in the other answer.


don't use the dreaded string-concatenation! In Groovy there's a nice replacement:

println """The row Id is: ${row.id}
    The word is: ${row.word}
    The number is: ${row.number}
    The decimal is: ${row.decimal}
    The date-time is: ${row.datetime}"""

Tags:

Groovy