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


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

Re: When to use dynamic binding over dynamic dispatch?

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: When to use dynamic binding over dynamic dispatch?
Date 2016-05-08 23:08 -0400
Organization Aioe.org NNTP Server
Message-ID <ngov04$aop$1@gioia.aioe.org> (permalink)
References (2 earlier) <dp8if4Fqm9cU1@mid.individual.net> <ngnb33$1rif$1@gioia.aioe.org> <ngnctb$pp9$1@dont-email.me> <ngniup$8u0$1@gioia.aioe.org> <dp9lveF3ctkU1@mid.individual.net>

Show all headers | View raw


On 5/8/2016 4:30 PM, Robert Klemme wrote:
> On 08.05.2016 16:37, Arne Vajhøj wrote:
>> On 5/8/2016 8:57 AM, Eric Sosman wrote:
>>> On 5/8/2016 8:23 AM, Arne Vajhøj wrote:
>>>> On 5/8/2016 6:24 AM, Robert Klemme wrote:
>>>>> On 04.05.2016 03:23, Arne Vajhøj 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 = method that can be overridden
>>>> final method = 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 = 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
> uses dynamic dispatch (late binding) as described in Wikipedia:
> https://en.wikipedia.org/wiki/Virtual_method

Well - it is actually mentioned as one possibility in the link
you provide so ...

>> 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
> your first statement matches the definition of "virtual method" that I
> have in mind much better because it speaks of "dynamic dispatch", i.e.
> does not make a statement about whether it can be overridden and instead
> focuses on invocation semantics.

I just find it very difficult to see:

public class Funny {
     public final void m() {
         System.out.println("I am funny");
     }
     public static void main(String[] args) {
         Funny o = new Funny();
         o.m();
     }
}

as a virtual method. And there is no need for dynamic dispatch.
Java just uses the same instruction as when dynamic dispatch
is needed.

Arne

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


Thread

When to use dynamic binding over dynamic dispatch? cdalten@gmail.com - 2016-05-02 18:08 -0700
  Re: When to use dynamic binding over dynamic dispatch? Sebastian <news@seyweiler.dyndns.org> - 2016-05-03 20:47 +0200
    Re: When to use dynamic binding over dynamic dispatch? Lew <lewbloch@gmail.com> - 2016-05-03 12:14 -0700
  Re: When to use dynamic binding over dynamic dispatch? Arne Vajhøj <arne@vajhoej.dk> - 2016-05-03 21:23 -0400
    Re: When to use dynamic binding over dynamic dispatch? Martin Gregorie <martin@address-in-sig.invalid> - 2016-05-04 10:48 +0000
    Re: When to use dynamic binding over dynamic dispatch? Robert Klemme <shortcutter@googlemail.com> - 2016-05-08 12:24 +0200
      Re: When to use dynamic binding over dynamic dispatch? Arne Vajhøj <arne@vajhoej.dk> - 2016-05-08 08:23 -0400
        Re: When to use dynamic binding over dynamic dispatch? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-08 08:57 -0400
          Re: When to use dynamic binding over dynamic dispatch? Arne Vajhøj <arne@vajhoej.dk> - 2016-05-08 10:37 -0400
            Re: When to use dynamic binding over dynamic dispatch? Robert Klemme <shortcutter@googlemail.com> - 2016-05-08 22:30 +0200
              Re: When to use dynamic binding over dynamic dispatch? Arne Vajhøj <arne@vajhoej.dk> - 2016-05-08 23:08 -0400
                Re: When to use dynamic binding over dynamic dispatch? Robert Klemme <shortcutter@googlemail.com> - 2016-05-09 08:16 +0200
            Re: When to use dynamic binding over dynamic dispatch? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-08 16:44 -0400
              Re: When to use dynamic binding over dynamic dispatch? Arne Vajhøj <arne@vajhoej.dk> - 2016-05-08 23:16 -0400
                Re: When to use dynamic binding over dynamic dispatch? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-09 00:39 -0400

csiph-web