Last active
March 5, 2018 14:59
-
-
Save ldaley/5429603 to your computer and use it in GitHub Desktop.
Groovy @DelegatesTo and type tokens.
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
Handler<T> handler(@DelegatesTo.Target(asType = true) Class<T> type, @DelegatesTo Closure<?> configurer) { | |
return new Handler() { | |
void handle(T object) { | |
configurer.delegate = object | |
configure.call(delegate) | |
} | |
} | |
} |
Agreed. I'll make some experiments around this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That seems doomed for user error. Let's see if we can avoid having to use imperative code.
It did originally, because I was just thinking about type tokens. That is,
asType
would only work on a Class param (anything else would be an error). In that context, I think the name makes sense. But know that we are talking about something bigger, I agree that the name doesn't make sense.I wish I could contribute here, but it's beyond my knowledge.
It seems like:
Would cover a lot of use cases if it could be made to work.