Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25654

Re: Java vs C++

From Thomas Richter <thor@math.tu-berlin.de>
Newsgroups comp.lang.java.programmer
Subject Re: Java vs C++
Date 2011-02-07 01:04 +0100
Organization InterNetNews at News.BelWue.DE (Stuttgart, Germany)
Message-ID <iincuv$ot9$1@news.belwue.de> (permalink)
References (3 earlier) <4d4d8322$0$41117$e4fe514c@news.xs4all.nl> <iil53i$q34$1@lust.ihug.co.nz> <iil5ed$10m$1@news.eternal-september.org> <iil74u$rac$1@lust.ihug.co.nz> <4d4f042b$0$23753$14726298@news.sunsite.dk>

Show all headers | View raw


Arne Vajhøj wrote:

>>> Templates in C++ are basically advanced macros--each invocation of a
>>> template type regenerates the class, so a Foo<int>  and a 
>>> Foo<double>  are
>>> two completely different things.
>>
>> They are different things in Java as well.
> 
> No. Same code.

I don't know in how far "same code" makes sense in Java in first place. 
The code that is created depends entirely on the JIT, and it may or may 
not generate the same code depending on how often it is called. For 
example, if it the JIT "sees" that the code is called with one specific 
type most of the time, it could create separate code just for this 
purpose and hence omit the type checks. And in C++, a compiler can also 
merge template instances because they are identical, i.e. function 
alike, i.e. for example they all operate on pointers.

Thus, I don't really see how that type of argument applies.

>>> Generics in Java are basically compile-time syntactic sugar to ensure
>>> type-safety of container types at compile time instead of waiting until
>>> you hit the code at runtime to get that dreaded ClassCastException.
>>
>> Same sort of thing in C++.

Not really. Generics are run-time checked, templates are compile-time 
checked. There is no "ClassCastException" in C++. If the class doesn't 
fit, the compiler will tell at compile time. Otherwise, the code will 
crash at run time - there is no additional check inserted as it is in 
java which tests whether the type-erased instance is of the proper type.

Greetings,
	Thomas

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Java vs C++ Silvio <silvio@moc.com> - 2011-02-05 18:04 +0100
  Re: Java vs C++ Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-07 16:21 +0800
  Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 12:28 +1300
  Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-08 09:22 +1300
    Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-07 17:25 -0500
      Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-08 16:08 +1300
  Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 12:24 +1300
    Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:03 +1300
      Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 21:18 -0500
    Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:15 -0500
  Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:55 +1300
  Re: Java vs C++ "javax.swing.JSnarker" <gharriman@boojum.mit.edu> - 2011-02-06 19:54 -0500
  Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:50 -0500
  Re: Java vs C++ Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-07 15:54 +0800
  Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 01:04 +0100
    Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:26 -0500
      Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 19:09 +1300
        Re: Java vs C++ Lew <noone@lewscanon.com> - 2011-02-07 07:29 -0500
        Re: Java vs C++ "Mike Schilling" <mscottschilling@hotmail.com> - 2011-02-06 22:52 -0800
  Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-06 16:35 +0100
    Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:51 +1300
    Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:01 +1300
      Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 14:53 +0100
    Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-07 19:52 -0500
    Re: Java vs C++ Lew <noone@lewscanon.com> - 2011-02-06 13:09 -0500
      Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 00:55 +0100
    Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:00 +1300
      Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 21:20 -0500
        Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:52 +1300
      Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 21:25 -0500
    Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:29 -0500
    Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 00:57 +0100
    Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 12:57 -0500
    Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 15:22 -0500
    Re: Java vs C++ "Mike Schilling" <mscottschilling@hotmail.com> - 2011-02-06 08:11 -0800
  Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 21:12 -0500
  Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 12:26 +1300
  Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 15:27 -0500
  Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-06 16:45 +0100

csiph-web