Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3684B18598 for ; Wed, 6 May 2015 08:26:07 +0000 (UTC) Received: (qmail 12477 invoked by uid 500); 6 May 2015 08:26:07 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 12444 invoked by uid 500); 6 May 2015 08:26:07 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 12434 invoked by uid 99); 6 May 2015 08:26:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 May 2015 08:26:07 +0000 X-ASF-Spam-Status: No, hits=1.0 required=5.0 tests=SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of dinko.srkoc@gmail.com does not designate 54.76.25.247 as permitted sender) Received: from [54.76.25.247] (HELO mx1-eu-west.apache.org) (54.76.25.247) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 May 2015 08:25:41 +0000 Received: from mail-ie0-f181.google.com (mail-ie0-f181.google.com [209.85.223.181]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 420E623173 for ; Wed, 6 May 2015 08:25:40 +0000 (UTC) Received: by iedfl3 with SMTP id fl3so9353598ied.1 for ; Wed, 06 May 2015 01:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=7BO3oeddHRS5iwbRegU54BSJYf7jVpTSGtQcbABtj24=; b=Bxv3RIoCaGE6/bERKQz2OhxMq1/5svUzqcnCWvTkyzlPRMU0aNv6WM7pbAKQZuXd39 xLaXXf9jDVss89DEa3xbhs5XCLIAegI5dXB/YAoTmDa1j7ZlDiJUMOccbXqxAgzTgG1H ktdzPwD5hecSs0GRbbp3KwaXmE0ioP0USltQDg5KlBUJbmxC62L0K7GnY0bY/d8TaKg9 i+fIRg+dztmjmoTTE3uDOl028qram1fVYUjWvOp7ENYU1ood0WqWcM03Ycshv9ADYZ53 BF+6Qn5bf6k1sRJGoy7nudW0DuR4HDZcWuqAs185ePh0uVomxPuTHX6xvL+7B6l4gbdc iMtA== X-Received: by 10.42.37.5 with SMTP id w5mr1370506icd.39.1430900739138; Wed, 06 May 2015 01:25:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.187.35 with HTTP; Wed, 6 May 2015 01:25:18 -0700 (PDT) In-Reply-To: <554900D8.9050408@gmail.com> References: <55439256.8010304@gmail.com> <554900D8.9050408@gmail.com> From: =?UTF-8?B?RGlua28gU3Jrb8SN?= Date: Wed, 6 May 2015 10:25:18 +0200 Message-ID: Subject: Re: respondsTo and constructors To: users@groovy.incubator.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org How about this: static IDownload createDownloader(Logger logger) { Download.constructors.findResult { ctor -> ctor.parameterTypes =3D=3D [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=C3=A9 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/ysb3= 3r/gradle/gradletest/internal/Unpacker.groovy#L37 > > Lines 37-43. > > > On 03/05/2015 15:56, Dinko Srko=C4=8D wrote: >> >> On 1 May 2015 at 16:48, Schalk Cronj=C3=A9 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=C3=A9 >>> Twitter / Ello / Toeter : @ysb33r > > > > -- > Schalk W. Cronj=C3=A9 > Twitter / Ello / Toeter : @ysb33r >