Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: When to use dynamic binding over dynamic dispatch? Date: Sun, 8 May 2016 22:30:29 +0200 Lines: 60 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net k0fDVliN3Lm/KYeRtxgsKAE0+Ypc7baFCXXaYCASUc31LekY0= Cancel-Lock: sha1:dEYa78NdRMpYekln4Rmv+QO57oo= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:34267 On 08.05.2016 16:37, Arne Vajh=C3=B8j wrote: > On 5/8/2016 8:57 AM, Eric Sosman wrote: >> On 5/8/2016 8:23 AM, Arne Vajh=C3=B8j wrote: >>> On 5/8/2016 6:24 AM, Robert Klemme wrote: >>>> On 04.05.2016 03:23, Arne Vajh=C3=B8j wrote: >>>>> All methods unless declared static or final are virtual in Java, >>>>> so dynamic dispatch is used all the time. >>>> >>>> Methods declared as "final" are virtual as well. >>> >>> Given that: >>> >>> virtual method =3D method that can be overridden >>> final method =3D method that can not be overridden >>> >>> then how can it be? >> >> class Super { >> public void method() {} >> } >> >> class Sub extends Super { >> public final void method() {} >> } >> >> ... >> >> Super obj =3D new Sub(); >> obj.method(); > > As a starting point I would not call Sub.method > a virtual method due to above definition. That seems to me a fairly uncommon definition. For me a virtual method=20 uses dynamic dispatch (late binding) as described in Wikipedia: https://en.wikipedia.org/wiki/Virtual_method > But per JLS such calls are "invocation mode virtual". Hence it's a virtual method in my book. > If we make the logical conclusion that methods that will be called > with invocation mode virtual are virtual methods, then the definition > of virtual methods is certainly different in Java. Certainly different from the definition you offered above. Ironically=20 your first statement matches the definition of "virtual method" that I=20 have in mind much better because it speaks of "dynamic dispatch", i.e.=20 does not make a statement about whether it can be overridden and instead = focuses on invocation semantics. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/