[ https://issues.apache.org/jira/browse/GROOVY-11168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17762823#comment-17762823 ]
Eric Milles edited comment on GROOVY-11168 at 9/7/23 5:16 PM: -------------------------------------------------------------- Assuming you could do this: {code:groovy} public <T> T stub(@DelegatesTo(type="T") Closure interactions) // or public <T> @DelegatesTo.Target T stub(@DelegatesTo Closure interactions) {code} Where do you source "T" from? If it comes from the return target only then how does the closure ever get one of these to delegate to? Or in your case, is it some dynamic facade that you want to appear like a "Foo" instance? was (Author: emilles): Assuming you could do this: {code:groovy} public <T> T stub(@DelegatesTo(type="T") Closure interactions) {code} Where do you source "T" from? If it comes from the return target only then how does the closure ever get one of these to delegate to? Or in your case, is it some dynamic facade that you want to appear like a "Foo" instance? > Ability to `@DelegatesTo` the return type > ----------------------------------------- > > Key: GROOVY-11168 > URL: https://issues.apache.org/jira/browse/GROOVY-11168 > Project: Groovy > Issue Type: Improvement > Reporter: Björn Kautler > Priority: Major > > With a method > {code:java} > public <T> T Stub(Closure interactions); {code} > that is then used like > {code:java} > Foo foo = Stub { /* configure the foo here */ } {code} > I'd like to be able to specify that the delegate is of type {{T}} so in the > given example of type {{{}Foo{}}}. > Currently we do this in Spock via IDE-specific gdsl/dsld Scripts. > But it would be nice if this would be supported out of the box. > (Ideally in 2.5 already, as we still have a 2.5 compatible artifact. :)) -- This message was sent by Atlassian Jira (v8.20.10#820010)