Created
November 4, 2016 02:06
-
-
Save AarjavP/d1b5b0d314e33cb015f09e1afb87ecaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.phly.groovy | |
import groovy.transform.CompileStatic | |
import groovy.transform.stc.ClosureParams | |
import groovy.transform.stc.FromAbstractTypeMethods | |
import groovy.transform.stc.SimpleType | |
@CompileStatic | |
class ClosureParamTest { | |
abstract class Foo { | |
abstract void firstSignature(int x, int y) | |
abstract void secondSignature(String str) | |
} | |
static void doIt(@ClosureParams(value = SimpleType, options = ['java.lang.String']) Closure cl) { | |
// .. | |
} | |
static void doSomething(@ClosureParams(value=FromAbstractTypeMethods, options=["Foo"]) Closure cl) { | |
// .. | |
} | |
static void doSomethingDifferent(@ClosureParams(value=FromAbstractTypeMethods, options=["net.phly.groovy.ClosureParamTest.Foo"]) Closure cl) { | |
// .. | |
} | |
public static void main(String[] args) { | |
doIt { s -> s.toUpperCase() } //compiles | |
doSomething { a, b -> a + b } //'works' but does not recognise a and b as int | |
doSomething { s -> s.toUpperCase() } //does not compile | |
doSomethingDifferent { a, b -> a + b } //'works' but does not recognise a and b as int | |
doSomethingDifferent { s -> s.toUpperCase() } //does not compile | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment