Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

Does one "call a method" when polymorphism is used?

Thread view: 
Stefan Ram - 04 Jan 2008 15:39 GMT
I wonder what the correct wording for the following situation is:

void print( final java.lang.Object object )
{ java.lang.System.out.println( object.toString() ); }
                               ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
 Without further thinking, one might say »The method
 "toString()" is being called here.«.

 However, according to the JLS, a methode is a specific member
 of a specifc class. »toString« above does not denotate such an
 entity, because for each invocation the method activated will
 be determined only at run-time.

 »toString()« yields a signature which is used at run-time to
 choose a method. Sometimes (in the case of other identifiers
 than »toString«) a method might not even be found in the
 target object's class, so actually this is at most a »call
 attempt«.

 To call this »to call a method« might be misleading, because
 it hides the indirection via late-binding and gives the wrong
 impression that »toString()« indicates a specific method of a
 specific class, while it really is only used to choose a
 method at run time.

 So, is there a more appropriate and precise wording?

 The first two ideas that come to my mind would be to say »to
 call a signature« or »to call an identifier«.

 I believe that the last idea is better, because »identifier«
 is used in the JLS3's description of the syntax of this
 invocation pattern and it also takes into consideration that
 the identifier expresses the intention of the author, while
 there might be multiple possible signatures depending on minor
 details for an identifier (like in »print("a")« and »print(2)«).

 But »to call an identifier« is unusual and also not contained
 in the usual sense of the verb to »call«.  The second problem
 might be addressed by using »to call /via/ an identifier«,
 which also hints at the indirection.
Mark Space - 04 Jan 2008 19:13 GMT
>   To call this »to call a method« might be misleading, because
>   it hides the indirection via late-binding and gives the wrong
>   impression that »toString()« indicates a specific method of a

I see "invoke" used a lot.
Stefan Ram - 04 Jan 2008 19:34 GMT
>I see "invoke" used a lot.

 Yes, but invoke /what/?

 My question was based on the observation that
 »to invoke a method« is too direct, because the
 signature does not represent a specific method.
Lew - 05 Jan 2008 00:52 GMT
>> I see "invoke" used a lot.
>
[quoted text clipped - 3 lines]
>   »to invoke a method« is too direct, because the
>   signature does not represent a specific method.

Sure it does.

It represents a specific method owned by a specific object.

> void print( final Object object )
> { System.out.println( object.toString() ); }

You really don't need the "java.lang." everywhere.

This is 'out' "calling the method" toString() on Object 'object'.

Naturally 'object' is going to use its own implementation of the method.
That's the whole freaking point.

Signature

Lew

Lew - 05 Jan 2008 00:54 GMT
>>> I see "invoke" used a lot.
>>
[quoted text clipped - 14 lines]
>
> This is 'out' "calling the method" toString() on Object 'object'.

I'm wrong.  It's the object that owns print() calling the method.

> Naturally 'object' is going to use its own implementation of the method.
> That's the whole freaking point.

Signature

Lew

A. Bolmarcich - 05 Jan 2008 00:59 GMT
>>I see "invoke" used a lot.
>
[quoted text clipped - 3 lines]
>   »to invoke a method« is too direct, because the
>   signature does not represent a specific method.

Then, how about "invoke a method on an object".  The
method signature and class of the object and runtime
determines the specific method.
A. Bolmarcich - 05 Jan 2008 01:14 GMT
>>>I see "invoke" used a lot.
>>
[quoted text clipped - 7 lines]
> method signature and class of the object and runtime
> determines the specific method.

Oops, I better correct that typo.

Then, how about "invoke a method on an object".  The
method signature and class of the object at runtime
determines the specific method.
andrewmcdonagh - 04 Jan 2008 20:19 GMT
>   I wonder what the correct wording for the following situation is:
>
[quoted text clipped - 37 lines]
>   might be addressed by using »to call /via/ an identifier«,
>   which also hints at the indirection.

From a OO PoV, the toString() is a 'Message' that is being sent to the
object. The object decides at runtime how to handle that Message,
depending upon the virtual nature of the method - i.e. has the method
toString() been over ridden?

An easy way of understanding this, is if you used Java's reflection
API to obtain a reference to the method from the obj's class.

Alternativitly, if you understand dynamically typed languages like
Python, Ruby, Smalltalk, etc., then these behave exactly like the
description above.  With the code like "obj.2String()" compiling, but
failing at runtime as the is no method defined that can handle the
Message.

Andrew
Andrew
Mark Rafn - 04 Jan 2008 22:45 GMT
>  I wonder what the correct wording for the following situation is:
>void print( final java.lang.Object object )
>{ java.lang.System.out.println( object.toString() ); }
>  Without further thinking, one might say "he method
>  "toString()" is being called here."

Yup, that's what I call it, and what everyone I talk to calls it.  Sometimes,
we say "invoke" rather than "call", but the object (of the sentence) is still
"the method toString on the Object referenced by object".

>  However, according to the JLS, a method is a specific member
>  of a specifc class.
>  "toString" above does not denotate such an entity, because for each
>  invocation the method activated will be determined only at run-time.

Different context.  Defining a method and invoking a method are not the same,
and "method" can mean different things in different situations.  

>  To call this to call a method might be misleading, because
>  it hides the indirection via late-binding and gives the wrong

Yup.  Welcome to English.  Almost no simple description is exactly correct.
And a lot of these ambiguities are far too ingrained to change, combined with
not actually harmful very often.

When you say "invoking a method starts with the VM determining the correct
method to invoke", it's obvious with a little thought that the two uses
of "method" in the sentence refer to different things.  

>  So, is there a more appropriate and precise wording?

Not in common use.  Where precision is needed, I'd recommend "declared method"
and "dispatched method".  This is close to the distinction between
getMethods() and getDeclaredMethods() in java.lang.Class.  Most of the time,
though, you can just say "method" and the listener will have to know what you
mean.

>  The first two ideas that come to my mind would be to say »to
>  call a signature« or »to call an identifier«.

identifier is wrong - there's only one type you can call, and it's a method.
signature isn't bad, but I doubt it'll catch on.

>  while
>  there might be multiple possible signatures depending on minor
>  details for an identifier (like in »print("a")« and »print(2)«).

Those details aren't minor - they can cause different code to be run as much
as any other signature change.

--
Mark Rafn    dagon@dagon.net    <http://www.dagon.net/>
Mark Space - 05 Jan 2008 01:45 GMT
> Not in common use.  Where precision is needed, I'd recommend "declared method"
> and "dispatched method".  This is close to the distinction between
> getMethods() and getDeclaredMethods() in java.lang.Class.  Most of the time,

I like "dispatch."  As A. Bolmarcich pointed out, an early term used for
 method invocation was "sending a message."  And messages are also
dispatched.

However, I saw a lot of people get confused, thinking that the message
was actually passed between two separate threads of execution.  So the
OO community hunted around for a better term and "invoke" is what they
came up with.  (I think.  History lesson taken with a chunk of salt.)
Stefan Ram - 05 Jan 2008 02:15 GMT
>OO community hunted around for a better term and "invoke" is what they

 According to my perception, »to invoke« is interchangeable
 with »to call«. »To invoke« is also common in other
 programming paradigms, such the procedural paradigm. One
 »invokes« a »procedure« or a »function«. There is nothing
 object-oriented about it.

 For example,

     »the semantic rules may even, in suitable
     circumstances, invoke themselves recursively«

   Revised Report on the Algorithmic Language
   ALGOL 68

     »The longjmp function is invoked to restore
     a nonexistent environment«

   ISO/IEC ISO/IEC 9899:1999, Programming languages -- C
Lew - 05 Jan 2008 03:24 GMT
>> OO community hunted around for a better term and "invoke" is what they
>
[quoted text clipped - 16 lines]
>
>     ISO/IEC ISO/IEC 9899:1999, Programming languages -- C

Either way - invoke a method, call a method - they're all fine, and all widely
accepted.

Signature

Lew

Mark Space - 05 Jan 2008 08:24 GMT
>   »invokes« a »procedure« or a »function«. There is nothing
>   object-oriented about it.

Not object oriented.  Just more than a standard call.  "Call" is an
assembly language op-code that pushes a return address on the stack and
then load a new address in the program counter.  (Also sometimes "js" or
"jsr".)

If it's more complicated than that, especially if it involves looking up
or search for bindings, then invoke is appropriate.  For example:

>       »The longjmp function is invoked to restore
>       a nonexistent environment«

Longjmp definitely does something more complicated than just call or return.

That's my thinking anyway.
Roedy Green - 05 Jan 2008 01:48 GMT
>  So, is there a more appropriate and precise wording?

The word "invoke" is often used.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.