You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by mfaustin <pd...@gmail.com> on 2015/09/26 23:56:38 UTC

How to add a method which accepts a generic type parameter?

Hi, everyone

I need through an AST Transformation add a method which accepts a generic
type parameter to script. 
For example:
I have a script

> @Test
> package test
>
> test([key: value, key: value])

I want to add the method

> private test(Map map) {
>     map.eah {...}
> }

But when I was trying to implement it I got a error: 

"A transform used a generics containing ClassNode java.util.Map <K extends
java.lang.Object -> java.lang.Object, V extends java.lang.Object ->
java.lang.Object> for the method private java.lang.Object 
test(java.util.Map map)  { ... } directly. You are not supposed to do this.
Please create a new ClassNode referring to the old ClassNode and use the new
ClassNode instead of the old one. Otherwise the compiler will create wrong
descriptors and a potential NullPointerException in TypeResolver in the
OpenJDK. If this is not your own doing, please report this bug to the writer
of the transform."

Is there is an article or example how add a method which accepts a generic
type parameter?



--
View this message in context: http://groovy.329449.n5.nabble.com/How-to-add-a-method-which-accepts-a-generic-type-parameter-tp5727838.html
Sent from the Groovy Users mailing list archive at Nabble.com.