Java generics and overloading with Groovy -


i write unit tests java application groovy, junit , easymock. in easymock there several overloaded methods capture() have been deprecated note "because of harder erasure enforcement, doesn't compile in java 7". methods take parameter object of type capture<t>. there exist, among others, following methods:

  • static boolean capture(capture<boolean> captured)
  • static boolean capture(capture<integer> captured)
  • ...
  • static <t> t capture(capture<t> captured)

this not allowed more in java if invoke code directly java right method gets invoked. e.g. when execute code

capture<myclass> myclasscapture = new capture<myclass>(); mockobject.somemethod(capture(myclasscapture)); 

the right method (the last in list) gets invoked.

on other hand, if invoke same code inside groovy, first method in list invoked , gives error in test. think has how java , groovy resolve methods. assumption java binds method @ compile time while groovy tries find method @ runtime , takes method can find (maybe first).

can explain happens here? nice understand different behaviour between java , groovy more precisely.

i fixed delegating call inside groovy java method job me:

public class easymockutils {      public static <t> t captureobject(capture<t> captureforobject) {         return easymock.capture(captureforobject);     } } 

is there maybe better way?

just hit issue myself using easymock 3.0. looks it's been resolved of easymock 3.2 renaming methods took wrapped primitives , leaving 1 remaining capture method.

check 3.2 docs more info: http://easymock.org/api/easymock/3.2/org/easymock/easymock.html#capture%28org.easymock.capture%29


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -