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 / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

casting

Thread view: 
Neil Lewis Morris - 07 Jan 2007 21:00 GMT
Dear All
With the following code from the Sun's Java tutorial could someone explain
the line with the 'if' statement

public Object findLargest(Object object1, Object object2) {
  Relatable obj1 = (Relatable)object1;
  Relatable obj2 = (Relatable)object2;
  if ( (obj1).isLargerThan(obj2) > 0)
     return object1;
  else
     return object2;
}
'Relatable' is an interface with method 'isLargerThan'. Why has obj1 in the
'if' statement in parenthesesthanks in advance
John W. Kennedy - 07 Jan 2007 21:30 GMT
> Dear All
> With the following code from the Sun's Java tutorial could someone explain
[quoted text clipped - 10 lines]
> 'Relatable' is an interface with method 'isLargerThan'. Why has obj1 in the
> 'if' statement in parenthesesthanks in advance

No need, no meaning. Probably leftover detritus from an earlier draft
reading

  public Object findLargest(Object object1, Object object2) {
    if (((Relatable)object1).isLargerThan((Relatable)obj2) > 0)
       return object1;
    else
       return object2;
  }

Signature

John W. Kennedy
"The blind rulers of Logres
Nourished the land on a fallacy of rational virtue."
  -- Charles Williams.  "Taliessin through Logres: Prelude"



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.