Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Alternatives languages on the JVM: which one or is there no alternative? Date: Tue, 26 Nov 2013 23:29:53 +0100 Lines: 58 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net +dfdIvRdK0ZkLc2QO0ROgAk9w90knJtc2bTgTm721cRUgWBoo= Cancel-Lock: sha1:UwZ4sGSj2eLMweKwDR7AFSvcegY= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: X-Antivirus: avast! (VPS 131126-0, 26.11.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:26629 On 26.11.2013 22:28, Volker Borchert wrote: > No language that is to run on the JVM can overcome its fundamental > shortcoming of missing multiple implementation inheritance. I have come to believe that omitting things that other languages do was actually a wise decision of the language designers. Avoiding MI might be one of them. Granted, you cannot use implementation inheritance. But sometimes not making these things easy is actually an advantage. At least I think that when comparing C++ and Java. The equation might calculate differently when comparing Java to other languages (Eiffel?). > While > this might not be a problem with everyday code, is _is_ a problem > if you are in low-level or framework stuff, for example if you have > class hierarchies where you want to offer mixed reference flavors - > your class C either ends up with two fields, one T and one to some > (X extends WeakReference) which contains another extra field for > the back reference to the containing C so that the C can be notified > of the X having been garbage collected and an extra two-word object > header, or with lots of duplicated code. What's wrong with this? class Foo { private Object ref; protected T getItem() { return ref instanceof WekReference ? ((WeakReference) ref).get() : (T) ref; } public T doSomeWork() { final T x = getItem(); // work ... return x; } } Then you need a pair of setters or one setter and one method which switches reference mode. This avoids having two fields and it avoids "lots of duplicated code". I do not know your notification requirements but I am sure you are aware of ReferenceQueue. Do you need notification the very moment an object is collected? How do you do that? The only way I can think of is having an additional thread blocking in ReferenceQueue.remove(). Not sure though why I then would place a field in the WeakReference - wouldn't it make more sense to let T know of its container / owner? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/