In this line of my Groovy code:
def document = someQuery().Document[0]
Method someQuery will return a Json Array and this worked well. Since editor doesn't know property, it underlined Document
, and shows a warning at [0]
, says:
'getAt' in 'org.codehaus.groovy.runtime.DefaultGroovyMethods' cannot be applied to '(java.lang.Integer)'
So what is the better way to do this to avoid this warning?
Strictly for .getAt(0)
and .getAt(-1)
, you can also use .first()
and .last()
, respectively, and Intellij will stop complaining.
Source: I just tried it. (See getAt doesn't expect an Integer here: code-completion)
def shortId(def longId){
longId?.toString()?.split('[/:]')?.last()
}
You probably have code that looks like:
def sql = //... (new/existing connection to the database)
sql.eachRow { row ->
//Do something...
}
Replace this with:
def sql = //... (new/existing connection to the database)
sql.eachRow { GroovyResultSet row ->
//Do something...
}
This will force your editor to look at methods from GroovyResultSet rather than methods with the same name attached to objects during groovy compilation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With