Path: csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.n-ix.net!news.belwue.de!not-for-mail From: Thomas Richter Newsgroups: comp.lang.java.programmer Subject: Re: Java vs C++ Date: Sun, 06 Feb 2011 16:45:05 +0100 Organization: InterNetNews at News.BelWue.DE (Stuttgart, Germany) Lines: 43 Message-ID: References: <4d4d585c$0$81476$e4fe514c@news.xs4all.nl> <4d4d60dc$0$23763$14726298@news.sunsite.dk> <4d4d8322$0$41117$e4fe514c@news.xs4all.nl> NNTP-Posting-Host: vpn-m-8d3a2f62.campus.uni-stuttgart.de Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.belwue.de 1297007108 29871 141.58.47.98 (6 Feb 2011 15:45:08 GMT) X-Complaints-To: news@news.belwue.de NNTP-Posting-Date: Sun, 6 Feb 2011 15:45:08 +0000 (UTC) User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100329) In-Reply-To: Xref: csiph.com comp.lang.java.programmer:26042 Joshua Cranmer wrote: > On 02/05/2011 11:13 PM, Lawrence D'Oliveiro wrote: >> They are different things in Java as well. > > The hell they aren't. In Java, there is only one instance of > LinkedList::add(T object). In C++, there are as many instances of > std::list::front as times you use it. I would say that's an implementation detail. A compiler/optimizer could check how many different implementations are needed and could merge those that are identical. Besides that, where you use an object in java, one would use a pointer or a reference in C++, and hence the code would be identical, allowing a good compiler to merge the implementations. C++ and java are quite different in their tradition how to use types, or what types are. Java has two sorts of types: First class citizens like int or double that are copied, and second class citizens like classes that are referenced. C++ doesn't have that, objects are objects and ints and classes are handled alike. > 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. True. >> The only time they become the >> same thing is in “erasures” and “raw types”, which are backward- >> compatibility mechanisms introduced to avoid breaking existing code that >> doesn’t know about generics. > > I think Java would likely have gone with much the same syntax even if > generics had been introduced in the beginning. That's really a speculation. One could also speculate that if java would have used or required generics from the beginning, they would be closer to C++ templates and would not use type erasure; instead, they would be parametrized classes as they are in C++. It's really speculation. Greetings, Thomas