The Artima Developer Community
Sponsored Link

Java Answers Forum
help

6 replies on 1 page. Most recent reply: Aug 22, 2002 7:32 AM by David Garton

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 6 replies on 1 page
Namita Das

Posts: 1
Nickname: namita
Registered: Aug, 2002

help Posted: Aug 6, 2002 3:19 AM
Reply to this message Reply
Advertisement
I want to have two routines in a class with same name, same signature but wiht different return type (One with void and another with int return type). Java1.1.8 is not allowing this and giving compilation error. Is there any way to solve it.I need these two routines badly or can I have the routine once with such a return tytpe do that it will work for both void and int type.


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: help Posted: Aug 6, 2002 5:24 AM
Reply to this message Reply
NO.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: help Posted: Aug 6, 2002 7:21 AM
Reply to this message Reply
How would you propose to use this routine? You could create a method that returns an Integer object or null to simulate this behavior, but you probably should explain (then rethink) why you need such a method.

Veerendra Shukla

Posts: 1
Nickname: j74
Registered: Aug, 2002

Re: help Posted: Aug 6, 2002 5:22 PM
Reply to this message Reply
With OO overloading concept, you can not have more than one method of the same signature.
Method return type does not get counted in method signature.
So just by changing the return type , you can not have same method twice in the given class.
~Veerendra

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: help Posted: Aug 7, 2002 3:08 AM
Reply to this message Reply
I think this question has been overloaded with to many answers having the same signature.

Ratul

Posts: 5
Nickname: rats
Registered: Aug, 2002

Re: help Posted: Aug 22, 2002 2:54 AM
Reply to this message Reply
Try to return something like object (java.lang.Object) from your routine(there can be only one such routine) -
Now if you want int - then type cast object to Integer and get the int value.Hope this helps you.

David Garton

Posts: 3
Nickname: davidkiwi
Registered: Aug, 2002

Re: help Posted: Aug 22, 2002 7:32 AM
Reply to this message Reply
You could include an int in the signature, that way if your method generates an int it will automatically go back to the calling method.

Flat View: This topic has 6 replies on 1 page
Topic: jsp problem: flush, print, println Previous Topic   Next Topic Topic: applets-package-images-appletviewer problem !!?

Sponsored Links



Google
  Web Artima.com   

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