Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

methods that return void..
pls, what is syntax for methods that return void?

for example cookie.setComment()...

I can do

cookie.setComment();

but how do you assign return to a var?  and why does a method like this
return void (i.e., nothing, right?) when setComment it would seem to me
is a string (same for other methods to set values for cookies..)

I mean get an error here..  (since method doesn't return a string..)

string comment = cookie.setComment();

so how do you do this?

void comment = setComment()??

obviously got an error here too.....  thank you...

Frances

Report this thread to moderator Post Follow-up to this message
Old Post
Frances Del Rio
06-03-05 09:00 PM


Re: methods that return void..
"Frances Del Rio" <fdr58@yahoo.com> wrote in message
news:42a094e5$1_1@x-privat.org...
>
> pls, what is syntax for methods that return void?
>
> for example cookie.setComment()...
>
> I can do
>
>     cookie.setComment();
>
> but how do you assign return to a var?  and why does a method like this
> return void (i.e., nothing, right?) when setComment it would seem to me is
> a string (same for other methods to set values for cookies..)
>
> I mean get an error here..  (since method doesn't return a string..)
>
>      string comment = cookie.setComment();
>
> so how do you do this?
>
> void comment = setComment()??
>
> obviously got an error here too.....  thank you...
>
> Frances

If something returns void it means it doesnt actually return anything,
therefore it is a syntax error to try and assign nothing to a variable.  If
you have a look at a method that returns void then you will probably see no
'return' in it, but if you do it will say 'return' and nothing else.
For your example, I would imagine setComment() takes a String as a
paramater, and the designer has decided to not return anything which makes
sense since all you are doing is passing a message in effect.  Some
programmers never return void, instead they take the opportunity to at least
return a boolean for sucess/failure but this is a design choice.
Anyway, the short answer is you cannot store nothing in a variable,
therefore assigning the result of a method that returns void to a variable
doesnt work.

Allan



Report this thread to moderator Post Follow-up to this message
Old Post
Allan Bruce
06-03-05 09:00 PM


Re: methods that return void..
On Fri, 03 Jun 2005 13:35:14 -0400, Frances Del Rio <fdr58@yahoo.com>
wrote:

>
>pls, what is syntax for methods that return void?
>
>for example cookie.setComment()...
>
>I can do
>
>     cookie.setComment();
>
>but how do you assign return to a var?  and why does a method like this
>return void (i.e., nothing, right?) when setComment it would seem to me
>is a string (same for other methods to set values for cookies..)
>
>I mean get an error here..  (since method doesn't return a string..)
>
>      string comment = cookie.setComment();
>
>so how do you do this?
>
>void comment = setComment()??
>
>obviously got an error here too.....  thank you...

Not sure what you are asking, but void methods do not return anything,
so attempting to assign something a value from that kind of function
will not compile.

If you need to get the comment from the cookie, I'm willing to bet
there's a function getComment()..

--
now with more cowbell

Report this thread to moderator Post Follow-up to this message
Old Post
Bryce
06-04-05 01:58 AM


Re: methods that return void..
Allan Bruce wrote:
> "Frances Del Rio" <fdr58@yahoo.com> wrote in message
> news:42a094e5$1_1@x-privat.org...
> 
>
>
> If something returns void it means it doesnt actually return anything,
> therefore it is a syntax error to try and assign nothing to a variable.  I
f
> you have a look at a method that returns void then you will probably see n
o
> 'return' in it, but if you do it will say 'return' and nothing else.
> For your example, I would imagine setComment() takes a String as a
> paramater, and the designer has decided to not return anything which makes
> sense since all you are doing is passing a message in effect.  Some
> programmers never return void, instead they take the opportunity to at lea
st
> return a boolean for sucess/failure but this is a design choice.
> Anyway, the short answer is you cannot store nothing in a variable,
> therefore assigning the result of a method that returns void to a variable
> doesnt work.

ok, many thanks for yr response..  I looked at other "set" methods in
Servlet API (specif. in HttpServletResponse & ServletResponse) and well,
they all return void..  I still think this is weird..  (but Bryce is
right, of course, specif. in my ex., there IS a getComment() method, and
probaby all the others have a "get" equiv. also..) again many thanks,
also to Bryce..  Frances



Report this thread to moderator Post Follow-up to this message
Old Post
Frances Del Rio
06-10-05 09:02 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:47 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.