File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return

 
cybel sheriden
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

return(y=z);

is the above statement legal , if yes then are we trying to assign z to y and returning z .
 
Ed Wallen
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, technically it is "legal" since the compiler will accept it, but it is sloppy coding. Separate the assignment and the return statement to two lines.

-Ed
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

return(y=z);

The above code is legal if y and z are boolean variables.
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I just ran this code:

With the result being:
int result: 9
String result: the test did work!!!


So these seem to work fine.
 
Ed Wallen
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surasak,

In response to your post:


return(y=z);

The above code is legal if y and z are boolean variables.


y & z do not have to be booleans. This is an assignment operation. This will work as long as z is assignable to y. However (I'll repeat again), even though this works it is sloppy coding.

-Ed
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I certainly agree that it's sloppy coding, and would never perform it in any usable class. I just created the example previously because of the boolean comment.
 
cybel sheriden
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test4
{
static int a=10;
static int amethod()
{int z=0;
return(a=z);//line L
}
public static void main(String[] args)
{
System.out.println("hello" + a + amethod());
}

}
result is hello 10 0

and i thought z value is returned as well assigned to a,but a still remains 10.
pls xplain.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a isn't set to 0 until amethod() is called; it isn't called until after the value of a is used in the println() statement. Switch the order of a and amethod(), and you'll get 0 0.
 
cybel sheriden
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
!oops that was simple ......i should have given a thought before posting
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic