The Artima Developer Community
Sponsored Link

Java Answers Forum
What advantages to overload procedure and function identifiers?

1 reply on 1 page. Most recent reply: Mar 17, 2002 2:41 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Bob

Posts: 4
Nickname: turshu
Registered: Mar, 2002

What advantages to overload procedure and function identifiers? Posted: Mar 17, 2002 2:02 PM
Reply to this message Reply
Advertisement
What advantages of being able to overload procedure and function identifiers?And why is this useful with operators


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: What advantages to overload procedure and function identifiers? Posted: Mar 17, 2002 2:41 PM
Reply to this message Reply
Sounds like you are talking about Pascal or C++.

Method overloading is just a convenience. It allows you to keep things more concise, terse and succinct while avoiding copious repetitive redundancies. In short, it is syntactic candy -- which is not a bad thing as long as you floss regularly. For instance, with overloading, you can simply do the following:
System.out.println( 32 );
System.out.println( 33.33 );
System.out.println( "Wasn't that fascinating?" );

However, without overloading, you'd need to do this:
System.out.printInt( 32 );
System.out.println(); // Still need the new lines.
System.out.printDouble( 33.33 );
System.out.println();
System.out.printString( "Wasn't that fascinating?" );
System.out.println();

Or something like that. Or at the very least, you'd need to do something like this:
System.out.println( Integer(32).toString() );
System.out.println( Double(33.33).toString() );
System.out.println( "Wasn't that fascinating?" );

Overloading is also very convenient for constuctors, where you often want to be able to construct your object with different types of information. For instance, the FileInputStream can be constructed with a File, a String or a FileDescriptor object.

Flat View: This topic has 1 reply on 1 page
Topic: reading text file through applet - secruity exception Previous Topic   Next Topic Topic: New to Java confusion with output/CheckBox and GUI?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use