Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 33274 invoked from network); 9 Aug 2010 11:33:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Aug 2010 11:33:32 -0000 Received: (qmail 91206 invoked by uid 500); 9 Aug 2010 11:33:31 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 90651 invoked by uid 500); 9 Aug 2010 11:33:27 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 90420 invoked by uid 99); 9 Aug 2010 11:33:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 11:33:24 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.212.43 as permitted sender) Received: from [209.85.212.43] (HELO mail-vw0-f43.google.com) (209.85.212.43) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 11:33:17 +0000 Received: by vws8 with SMTP id 8so6279735vws.30 for ; Mon, 09 Aug 2010 04:32:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=JMZX+cg/ZMH7dzBrLYuTyVcRqZh1i/axBIFQOvhWC8U=; b=NsMQfMDsulGN55+Iml9vi9HxBrKbedVak84wBrcSV7881tF6+7iFhJjr/Yy+9F18Wx 8UqG20dNP3bInKWRqmqjiKoPkLYI4x0z4C//i1E5B9gGx452BB89hZFHRwV3F5ZSqIPQ rN/s6A+iONZkObCjD6vkYw3dFJxHcv4W0OOQo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Axu0P9FDXjrAb5u4EiZEAqAKRByKu6XNwwLuGRR+XUXSHxQTPo2aodo+IyTHiNpbv4 VFvnc92YUxnG8D5R0m+ybsxI9S51FQ+5HloXHA0PtVa/0SKcupZrtIvmbdWl8NuNExKq 2IGdXDOPkl3OG1a0Wvwy6q63lDiaA8ROKHjV4= MIME-Version: 1.0 Received: by 10.220.169.21 with SMTP id w21mr9352268vcy.202.1281353576862; Mon, 09 Aug 2010 04:32:56 -0700 (PDT) Received: by 10.220.161.81 with HTTP; Mon, 9 Aug 2010 04:32:56 -0700 (PDT) In-Reply-To: References: <20100806224439.4728D23889EA@eris.apache.org> Date: Mon, 9 Aug 2010 12:32:56 +0100 Message-ID: Subject: Re: svn commit: r983137 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java From: sebb To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On 9 August 2010 04:45, James Carman wrote: > On Sun, Aug 8, 2010 at 10:04 PM, sebb wrote: >> >> Yes. >> >> But the current change makes it harder to find errors. >> >> Previously, the compiler would warn about unsafe casts; with the >> current implementation the warnings are suppressed. >> IMO this is a retrograde step. >> >> I expect generic library routines to create a Map that agrees with the >> generic types, not allow the types to be violated. >> >> Generics are partly about allowing the compiler to check that class >> casts cannot happen. >> This relies on generic methods behaving themselves, which the current >> implementation does not. >> > > With type erasure, I believe it's impossible (correct me if I'm > wrong)to determine the exact type of "K" and "V" in the code so that > we could check the type safety of the keys/values passed in. =A0So, we > would either have to change the method signature to: > > public Map toMap(Class keyType, Class valueType, Object[] arra= y); > > or, we could add a warning to the documentation for the method: > > "Warning: This code does not (and cannot) check the type safety of the > keys/values against the method's type variables (). =A0Thus, if you > are expecting a Map to be returned, but you pass in a > MapEntry[] (or the analogous Object[][]), the method > will not fail, but you will get a ClassCastException at runtime." > > Other than that, the only other option that I can see is to back out > the change completely, but then we lose the "syntactic sugar" that it > adds. =A0I personally like the sugar. The problem is that this sugar rots the teeth of the generic type-checking system. > So, I'd say let's go with the warning in the docs. Why not split the code into two methods: public static Map toMap(Map.Entry[] array) and public static Map toMap(Class keyType, Class valueType, Object[][] array) Both methods can be made type-safe. Failing that, the current method could at least check that all pairs are of the same types, and AFAICT one can still add the first method as an overloaded version which is type-safe. I think the Object[][] version should also check that the array entries are exactly length 2 - it's nonsense to pass in a longer array. > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org