Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C5DD8183FD for ; Thu, 28 Apr 2016 19:31:33 +0000 (UTC) Received: (qmail 7855 invoked by uid 500); 28 Apr 2016 19:31:32 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 7747 invoked by uid 500); 28 Apr 2016 19:31:32 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 7735 invoked by uid 99); 28 Apr 2016 19:31:32 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Apr 2016 19:31:32 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id B3FB8C0257 for ; Thu, 28 Apr 2016 19:31:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.099 X-Spam-Level: * X-Spam-Status: No, score=1.099 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id McwPVlvbDF-7 for ; Thu, 28 Apr 2016 19:31:28 +0000 (UTC) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.24]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id E7CC35F19A for ; Thu, 28 Apr 2016 19:31:27 +0000 (UTC) Received: from [192.168.178.20] ([88.65.147.210]) by mrelayeu.kundenserver.de (mreue101) with ESMTPSA (Nemesis) id 0LtFON-1bfpby1ok7-012tWJ for ; Thu, 28 Apr 2016 21:31:25 +0200 Subject: Re: [configuration2]: AbstractConfiguration::getArray To: Commons Users List References: <57211173.9000409@web.de> <57211476.3070200@oliver-heger.de> From: Oliver Heger Message-ID: <57226527.6020105@oliver-heger.de> Date: Thu, 28 Apr 2016 21:31:51 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:Oc1om60atY89yyQCQlByygYidWzffT6qiSlRUL4E5UPvLBNN5eQ 6BWJ7Y3GREoIVqmXWPsfbhg92GXxnlK78gmU+PCCGBQY5DLaJssr4v0dYsKM4FQoVYG/BII Pohfeowx6/HJfDVA1hsDY3AVBS5qW4woSdpdRytlrvnWQvYHPE2nHay1ZXRHMgYlErYfAKF UTd4SfZodGPdl9beilNag== X-UI-Out-Filterresults: notjunk:1;V01:K0:yWrWpz2brs4=:oIIdxDz8ODNHgYBWwyBPKE OSKi2G+aViTJvyGEVxTfx3nWZQmeuSNrk3eeuXncE7TOIR+1ziHU6ya9NUwLIJ6ugdFQv5eon mTFDlaWDEVxTC8zXvkoGlyZBwnfYMyL/4jz6rWmbgvkE2kU3H/1Q6qcZIa5N+GXenFnWUSEle kZtQEqPnnsyi/sRvViH3AGlbhFLFa2I19pV0gNd+8K9AN2RkuCLxK/TUqL8yg6+E/rSeSiYWW tqXQiwdgxKvt3L+pzT0Z+YHvYxHuw3mHUYK3XPtsMZjkQNNsrtB42XGJVWNoS0kCleLTY1XA/ W9lTpq9DyKRdLEfoEmB5sugiVcp/QOtUf4ps5bif9HXHP+cLguunSMPIozlEVdlNn3VyBtdHy 0DpolscCQ9aTCIsJ9tKt9DFBunBoExhfPlMVMD9oATVAX9pdP4tLJgC/Z3YNkmmACOzvoEtjc 0RxcZbHnL1RpR+MAh6nscSBY7bVYNkGsem83JZtyr7QYPQPz1RtrpoQiItJd1Ia9idYQH2KQ/ 2oXXlS3deybxOG7g9oO3bu5ekBJxF/KD+i5U8mNrX5YYKGOjliz/Qmmdodj6MXSL8wDgZL3W0 E6yWQvrmByl4oqo+L1MWiAGB19d5ccTZkFnrU4udZogjlWBJobhJHwMN0QNP+ZUalvRgBn0AD mFz04WB1YOAxPBsKOPlELFJWGY70c21ySANtSsywlF+NfO0xVttU/USin33t72NmpT3UjVDWK DbK/+3c7UwKaSLvg Hi Jörg, Am 28.04.2016 um 16:34 schrieb Jörg Schaible: > Chas Honton wrote: > >> Try casting Object[] to long[]. The compiler and the runtime will >> complain. > > It is not about a cast, it's about returning the proper object. And it has > nothing to do with primitives, because you cannot cast e.g. Object[] to > String[] either. my first idea was the generic version, too. However, as Chas said, it is not possible to make a method with such a signature return an array of primitives. After type erasure, you have public Object[] toArray(Class cls, String key) and a primitive array is not an Object[]. Oliver > >> >>> On Apr 27, 2016, at 11:59 PM, Jörg Schaible >>> wrote: >>> >>> Hi Oliver, >>> >>> Oliver Heger wrote: >>> >>>> Hi Rainer, >>>> >>>>> Am 27.04.2016 um 21:22 schrieb Rainer Hirschmiller: >>>>> Hi. >>>>> >>>>> I wonder why AbstractConfiguration::getArray(cls, key) returns a single >>>>> object, not an array of objects? Can somebody explain why the caller >>>>> have to make an explicit cast? >>>>> >>>>> e.g. >>>>> AbstractConfiguration &configuration = ....; >>>>> >>>>> Object obj = configuration.getArray(String.class, "key); >>>>> // expected Object[] obj = configuration.getArray(String.class, "key); >>>> >>>> the explanation can be found in the Javadocs of the ConversionHandler >>>> interface which is used behind the scenes. Citing from the docs of the >>>> toArray() method: >>>> >>>> "Note that the result type of this method is Object; because this method >>>> can also produce arrays of a primitive type the return type Object[] >>>> cannot be used." >>> >>> That does not explain, why the method is not declared using generics: >>> >>> public T[] toArray(Class cls, String key); >>> >>> Cheers, >>> Jörg >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>> For additional commands, e-mail: user-help@commons.apache.org >>> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org