<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-11200164.post1203632720875867405..comments</id><updated>2009-05-14T19:02:39.099-04:00</updated><title type='text'>Comments on Nirav's Contemplations: Scala v/s Java arrays</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://blog.nirav.name/feeds/1203632720875867405/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html'/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-11200164.post-1904328820981513107</id><published>2009-05-14T19:02:00.000-04:00</published><updated>2009-05-14T19:02:00.000-04:00</updated><title type='text'>A[] a1 = new A[1];
B[] b1 = new B[1];
b1 = a1; //T...</title><summary type='text'>A[] a1 = new A[1];&lt;br /&gt;B[] b1 = new B[1];&lt;br /&gt;b1 = a1; //Type mismatch&lt;br /&gt;&lt;br /&gt;In this example you cannot cast the A[] to a B[] because A is not a B. The other way works fine though.&lt;br /&gt;&lt;br /&gt;a1 = b1;&lt;br /&gt;&lt;br /&gt;..., but then it blows up when inserting a simple A ...&lt;br /&gt;&lt;br /&gt;a1[0] = new A();&lt;br /&gt;&lt;br /&gt;You can also force the A[] to B[] cast. This will of course blow up.&lt;br /&gt;&lt;br /&gt;b1 = </summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/1904328820981513107'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/1904328820981513107'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242342120000#c1904328820981513107' title=''/><author><name>thoredge</name><uri>http://www.blogger.com/profile/17721005437698193088</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-6140822824853486764</id><published>2009-05-14T10:17:00.000-04:00</published><updated>2009-05-14T10:17:00.000-04:00</updated><title type='text'>If it is not truly a generics issue, can you enlig...</title><summary type='text'>If it is not truly a generics issue, can you enlighten me why the example code in post compiles without error and why following code does't?&lt;br /&gt;&lt;br /&gt;A[] a1 = new A[1];&lt;br /&gt;B[] b1 = new B[1];&lt;br /&gt;b1 = a1; //Type mismatch&lt;br /&gt;&lt;br /&gt;Because that's the only issue I have problem with.</summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/6140822824853486764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/6140822824853486764'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242310620000#c6140822824853486764' title=''/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13398947556794333606'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-8365418939370678215</id><published>2009-05-14T03:57:00.000-04:00</published><updated>2009-05-14T03:57:00.000-04:00</updated><title type='text'>I agree with previous posters. This has nothing to...</title><summary type='text'>I agree with previous posters. This has nothing to do with generics, merely a legacy of java arrays, which are with us since 1995. (Don't you think it's kind of old news in mid-2009?)&lt;br /&gt;&lt;br /&gt;Also, arrays of course have types, distinct from their component types. (Here is even how these types are represented in bytecode, for example [I is int[], [[D a double[][] etc).&lt;br /&gt;&lt;br /&gt;If this was </summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8365418939370678215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8365418939370678215'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242287820000#c8365418939370678215' title=''/><author><name>Dimitris Andreou</name><uri>http://www.blogger.com/profile/07286834543482860937</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-7710618583659868077</id><published>2009-05-13T19:45:00.000-04:00</published><updated>2009-05-13T19:45:00.000-04:00</updated><title type='text'>Think I wasn't precise enough, I am not disagreein...</title><summary type='text'>Think I wasn't precise enough, I am not disagreeing about generics in Java for types isn't a problem, it is generics and array as the post title says which attracts confusion. &lt;br /&gt;&lt;br /&gt;I don't get any benefit out of generifying the array (by that I mean, a method signature with generic array types in it).</summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/7710618583659868077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/7710618583659868077'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242258300000#c7710618583659868077' title=''/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13398947556794333606'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-8746862973284433641</id><published>2009-05-13T18:08:00.000-04:00</published><updated>2009-05-13T18:08:00.000-04:00</updated><title type='text'>You can't "generify" an array.
If you specify a ge...</title><summary type='text'>You can&amp;#39;t &amp;quot;generify&amp;quot; an array.&lt;br /&gt;If you specify a generic variable/parameter, it&amp;#39;s normal that you can put subclasses to it.&lt;br /&gt;&lt;br /&gt;new ArrayList&amp;lt;A&amp;gt;().add(new B());&lt;br /&gt;new ArrayList&amp;lt;A[]&amp;gt;().add(new B[1]);&lt;br /&gt;&lt;br /&gt;There&amp;#39;s no difference in here, no breaking of the generics: B[] is a subclass of A[], because B is a subclass of A.</summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8746862973284433641'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8746862973284433641'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242252480000#c8746862973284433641' title=''/><author><name>Hardcoded</name><uri>http://www.blogger.com/profile/17425860638556714043</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-8080818889214709937</id><published>2009-05-13T12:22:00.000-04:00</published><updated>2009-05-13T12:22:00.000-04:00</updated><title type='text'>Hardcoded, thoredge:

This is indeed generics issu...</title><summary type='text'>Hardcoded, thoredge:&lt;br /&gt;&lt;br /&gt;This is indeed generics issue, IMO. &lt;br /&gt;The raw arrays in Java are covariant by default. Which is fine, but when I generify them I expect it to be non-variant. Just like List &amp;lt;String&amp;gt; is not List&amp;lt;Object&amp;gt; without view bounds, arrays should also not be co-variant unless of course I add bounds and wildcards. Why should I use generics if I wanted to have </summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8080818889214709937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8080818889214709937'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242231720000#c8080818889214709937' title=''/><author><name>Nirav Thaker</name><uri>http://www.blogger.com/profile/07204297663478577248</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13398947556794333606'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-9094438728698185359</id><published>2009-05-13T12:03:00.000-04:00</published><updated>2009-05-13T12:03:00.000-04:00</updated><title type='text'>Have to agree with Hardcoded here. This has nothin...</title><summary type='text'>Have to agree with Hardcoded here. This has nothing to do without generics. A simpler example of this problem can be expressed this way:&lt;br /&gt;&lt;br /&gt;public class UnGenerics {&lt;br /&gt;    static class A {&lt;br /&gt;    }&lt;br /&gt;    static class B extends A {&lt;br /&gt;    }&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        insert(new A(), new B[1]);&lt;br /&gt;    }&lt;br /&gt;    private static void insert(A a,</summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/9094438728698185359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/9094438728698185359'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242230580000#c9094438728698185359' title=''/><author><name>thoredge</name><uri>http://www.blogger.com/profile/17721005437698193088</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-8033117175658867778</id><published>2009-05-13T11:18:00.000-04:00</published><updated>2009-05-13T11:18:00.000-04:00</updated><title type='text'>The problem you're describing has nothing todo wit...</title><summary type='text'>The problem you&amp;#39;re describing has nothing todo with Generics, but with the array hierarchy.&lt;br /&gt;&lt;br /&gt;The JLS defines that B[] is a subclass of A[]. This causes a lot of confusion and you&amp;#39;re right with your critic about it.&lt;br /&gt;&lt;br /&gt;But this is contrary to generic types, which are, per default, invariant:&lt;br /&gt;&lt;br /&gt;static List&amp;lt;T&amp;gt; merge(List&amp;lt;T&amp;gt; l1, List&amp;lt;T&amp;gt; l2, List&amp;lt</summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8033117175658867778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/8033117175658867778'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242227880000#c8033117175658867778' title=''/><author><name>Hardcoded</name><uri>http://www.blogger.com/profile/17425860638556714043</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-11200164.post-3111303291797019311</id><published>2009-05-13T11:17:00.000-04:00</published><updated>2009-05-13T11:17:00.000-04:00</updated><title type='text'>Java arrays are covariant because James Gosling (a...</title><summary type='text'>Java arrays are covariant because James Gosling (and friends) thought it was a good idea at the time.  The problem is that Java 1 *didn't* have generics, so the only way to provide utility methods like System.arraycopy was to make arrays covariant in their value type.  It was actually worse back in Java 1: there were *no* runtime checks for array storage problems.  Thus, your code would probably </summary><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/3111303291797019311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/11200164/1203632720875867405/comments/default/3111303291797019311'/><link rel='alternate' type='text/html' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html?showComment=1242227820000#c3111303291797019311' title=''/><author><name>Daniel Spiewak</name><uri>http://www.blogger.com/profile/17323566514229790079</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://blog.nirav.name/2009/05/scala-vs-java-arrays.html' ref='tag:blogger.com,1999:blog-11200164.post-1203632720875867405' source='http://www.blogger.com/feeds/11200164/posts/default/1203632720875867405' type='text/html'/></entry></feed>