Skip to content

Instantly share code, notes, and snippets.

@abargnesi
Created September 19, 2013 19:30
Show Gist options
  • Save abargnesi/6628656 to your computer and use it in GitHub Desktop.
Save abargnesi/6628656 to your computer and use it in GitHub Desktop.
Groovy snippet that causes type error on groovy 2.1.7 (invokedynamic version).
interface ServiceA {}
interface ServiceB {}
interface ServiceC {}
interface ServiceD {}
interface ServiceE {}
interface ServiceF {}
interface ServiceG {}
static Expando getRefs(Integer i, Class<?>... ifaces) {
Expando e = new Expando()
ifaces.each {
def impl = new Object()
def name = it.simpleName
e.setProperty(name[0].toLowerCase() + name[1..-1], impl)
}
e
}
getRefs(1, ServiceA.class, ServiceB.class, ServiceC.class, ServiceD.class, ServiceE.class, ServiceF.class, ServiceG.class)
// Causes stacktrace on Groovy 2.1.7 (indy/invokedynamic), Java 1.7.0_40:
// Caught: java.lang.IllegalArgumentException: target and fallback types must match: (Object,Object,Object,Object,Object,Object,Object,Object,Object)Object != (Class,int,Class,Class,Class,Class,Class,Class,Class)Object
// java.lang.IllegalArgumentException: target and fallback types must match: (Object,Object,Object,Object,Object,Object,Object,Object,Object)Object != (Class,int,Class,Class,Class,Class,Class,Class,Class)Object
// at varargs_indy.run(varargs_indy.groovy:19)
// Compiled as: groovy -cp groovy-all-2.1.7-indy.jar --indy varargs_indy.groovy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment