Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Sebastian Newsgroups: comp.lang.java.programmer Subject: Re: Problem with generics and dynamic array copy Date: Fri, 22 Jul 2011 20:36:25 +0200 Organization: albasani.net Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net 1jUUKDh8+2+gjpZYMWIVzggOf8gn1wkvHFs+nBkmY7p0zhGDZ/PfJWjtbgbhNrwhZK9wr0lbqITlJNKeZOnduuRufNXJSwyoL4f8nz8cqAHrDuJ9ZkR+SC2C0J11WEAV NNTP-Posting-Date: Fri, 22 Jul 2011 18:36:26 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="UEoDCxxlb8QAa1Vkgww6o88yOEplDamA8USizZMOb0OfFczwjqr/SiKo632rH1tkCgxwTB+hGb6WZkdJDIpPWjviimlVgaw04wzE+o5Yq/kA8SVsAMKnHso3qDjz1cWq"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Cancel-Lock: sha1:jetNo4sCiIt4wEgkKrwDEcZVIyU= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6409 Am 22.07.2011 20:23, schrieb markspace: > On 7/22/2011 10:30 AM, Sebastian wrote: > >>> public static final T[] arraycopy( T[] src ) >>> { >>> Class componentType = src.getClass().getComponentType(); // !!!! > > > RTFM. getComponentType() returns Class, not Class. > > > > > public Class getComponentType() > > Returns the Class representing the component type of an array. If this > class does not represent an array class this method returns null. > well, yes, but given that src.getClass() must give one the class object for arrays with component type T, why is the compiler not smart enough to infer that the unknown class parameter in the return value of getComponentType() must be T? As a human I can see that, that's why I can cast to Class, but I don't believe that I'm smarter than javac... -- Sebastian