Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: v_borchert@despammed.com (Volker Borchert) Newsgroups: comp.lang.java.programmer Subject: Re: Alternatives languages on the JVM: which one or is there no alternative? Date: 29 Nov 2013 23:22:37 GMT Organization: Private site at Eddersheim, Germany Lines: 79 Distribution: world Message-ID: References: X-Trace: individual.net hAQpIXy5QIMFn+DtFkSCMAV0fSkYQ1eC8dftCNwYk0lsZIM6Ry Cancel-Lock: sha1:wyhNNb43OG8AXtIYfyxanJ5+gzE= Xref: csiph.com comp.lang.java.programmer:26676 Robert Klemme wrote: > What does dynamic_cast in C++ do differently? As far as I am informed > it involves a type check as well. I mean, you can have the same in Java > by catching the exception (which is what you need to do in C++ IIRC). No you don't, that is exactly the raison d'etre of dynamic_cast. if (o instanceof C) { final C c = (C) o; // do something with c } does _two_ typechecks final C c = dynamic_cast(o); if (c != null) { // do something with c } would do _one_ typecheck and a cheap IFNONNULL > > class Foo { > > // nonstatic inner class uzes 4 bytes for the > > // implicit this$0 and 4 more bytes padding > > class TPtr extends WeakReference { > > Foo foo() { > > return Foo.this; > > } > > } > > > > void gced() { > > } > > } > > Since Foo inherits Object you could as well make Foo inherit > WeakReference avoiding the additional bytes per instance. Sorry, I forgot the "extends Bar". > I find it difficult to discuss this without knowing more about your > requirements and situation. But then again, maybe you don't want or > cannot disclose that. One example, for a Cache that supports mixed flavor Value references, and a subclass which additionally has entries doubly linked, somewhat similar to LinkedHashMap, I want AbstractEntry WeakReference | | | | / \ | +---------------+---+----------+-------------+ | | | | | | | | | AbstractLinkedEntry StrongEntry | | | | | | | | | | +---------------+---+----------+ +--+---+--+ | \ / \ / | | | | | | | StrongLinkedEntry WeakEntry | | | | +------------------------------+---+--------------+ \ / | | WeakLinkedEntry (soft flavor omitted for safe of readability) -- "I'm a doctor, not a mechanic." Dr Leonard McCoy "I'm a mechanic, not a doctor." Volker Borchert