groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schalk Cronjé <ysb...@gmail.com>
Subject Re: respondsTo and constructors
Date Wed, 06 May 2015 21:14:50 GMT
Thank you Dinko.

On 06/05/2015 09:25, Dinko Srkoč wrote:
> How about this:
>
>      static IDownload createDownloader(Logger logger) {
>          Download.constructors.findResult { ctor ->
>              ctor.parameterTypes == [Logger, String, String] as Class[] ?
>                  ctor.newInstance(logger, 'GradleTestPlugin','1.0') :
>                  ctor.newInstance('GradleTestPlugin','1.0')
>          }
>      }
>
> Cheers,
> Dinko
>
> On 5 May 2015 at 19:41, Schalk Cronjé <ysb33r@gmail.com> wrote:
>> I did this for the time being. It works, but I'm not happy about it.
>>
>> https://github.com/ysb33r/gradleTest/blob/master/src/main/groovy/org/ysb33r/gradle/gradletest/internal/Unpacker.groovy#L37
>>
>> Lines 37-43.
>>
>>
>> On 03/05/2015 15:56, Dinko Srkoč wrote:
>>> On 1 May 2015 at 16:48, Schalk Cronjé <ysb33r@gmail.com> wrote:
>>>> I cannot figure out how to check for a constructor using respondsTo. If I
>>>> had the following
>>>>
>>>> class ABC {
>>>>     ABC(String s, File f) {}
>>>> }
>>>>
>>>> How can I use respondsTo to see if the constructor exists?
>>> It appears that you cannot. There's a
>>> `MetaClassImpl#retrieveConstructor(Class[])` that may help, or one can
>>> always fallback to Java reflection API.
>>>
>>> Cheers,
>>> Dinko
>>>
>>>> --
>>>> Schalk W. Cronjé
>>>> Twitter / Ello / Toeter : @ysb33r
>>
>>
>> --
>> Schalk W. Cronjé
>> Twitter / Ello / Toeter : @ysb33r
>>


-- 
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r


Mime
View raw message