Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25611
| From | "javax.swing.JSnarker" <gharriman@boojum.mit.edu> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java vs C++ |
| Date | 2011-02-06 19:54 -0500 |
| Organization | media lab? |
| Message-ID | <iinft1$95e$1@speranza.aioe.org> (permalink) |
| References | (5 earlier) <iil5ed$10m$1@news.eternal-september.org> <iil74u$rac$1@lust.ihug.co.nz> <4d4f042b$0$23753$14726298@news.sunsite.dk> <iincuv$ot9$1@news.belwue.de> <iineik$3tp$10@lust.ihug.co.nz> |
On 06/02/2011 7:32 PM, Lawrence D'Oliveiro wrote: > In message<iincuv$ot9$1@news.belwue.de>, Thomas Richter wrote: > >> There is no "ClassCastException" in C++. > > Yes there is. It’s called “bad_cast”. Where do you think Java got the idea > from? dynamic_cast<foo>(bar) can throw this if bar is not really a foo. But C++ lets you use the unsafe old (foo)bar cast from C, and if bar is not really a foo, welcome to undefined behaviorville. Java doesn't let that happen: the cast syntax is (Foo)bar but the semantics is that of dynamic_cast: bar is a Foo or an exception gets thrown. The only way to come close to C's unsafe cast with Java is to muck about with serialization, to alter a serialized representation of a Bar to claim to be of class Foo instead and then deserialize it. Most likely you get a broken Foo and exceptions thrown, but not a VM crash. The main reason you'd try that is to try to break some existing Java program -- hack it, crack it, virus someone's VM. There's never any use for that in normal programming that I am aware of. -- In <iijn58$ccs$1@news.albasani.net>, Lew admitted: > The JLS is obfuscatory in parts
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
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++ 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++ 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++ 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++ 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