Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail From: Lawrence D'Oliveiro Newsgroups: comp.lang.java.programmer Subject: Re: Java vs C++ Followup-To: comp.lang.java.programmer Date: Mon, 07 Feb 2011 15:08:21 +1300 Organization: Geek Central Lines: 31 Message-ID: References: <4d4d585c$0$81476$e4fe514c@news.xs4all.nl> <4d4d60dc$0$23763$14726298@news.sunsite.dk> <4d4d8322$0$41117$e4fe514c@news.xs4all.nl> <4d4f43d9$0$23755$14726298@news.sunsite.dk> NNTP-Posting-Host: 118-92-86-70.dsl.dyn.ihug.co.nz Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: lust.ihug.co.nz 1297044501 8445 118.92.86.70 (7 Feb 2011 02:08:21 GMT) X-Complaints-To: abuse@ihug.co.nz NNTP-Posting-Date: Mon, 7 Feb 2011 02:08:21 +0000 (UTC) User-Agent: KNode/4.4.7 Xref: csiph.com comp.lang.java.programmer:25484 In message <4d4f43d9$0$23755$14726298@news.sunsite.dk>, Arne Vajhøj wrote: > On 06-02-2011 18:28, Lawrence D'Oliveiro wrote: > >> In message, Joshua Cranmer >> wrote: >> >>> Try, for example, implementing both List and List >>> in the same class. Java will tell you that you cannot do it. C++, on the >>> other hand, wouldn't bat an eye. >> >> Why does Java impose such a pointless restriction? > > It is given by the use of type erasure. Which is purely a backward-compatibility mechanism. If I were to take two copies of the definition of List, and in one take out and replace E with String, and in the other replace it with Character, Java would have no problem letting me declare a class that implements both interfaces. But try doing it directly with the generic, and it won’t. Java draws a distinction between the two cases where there really shouldn’t be any distinction. That’s what generics are for, after all—they’re there to save work for the programmer, not create it. See, Java started out as not wanting to be like C++: it would take the good stuff from C++, and leave the rest behind. But now, with the addition of generics, it’s clear Java wants to be more like C++ after all. The only thing holding it back is not deliberate design choices over functionality, but the dead hand of backward compatibility.