• Post Reply Bookmark Topic Watch Topic
  • New Topic

value returned by function  RSS feed

 
Akshay Bhatia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code,

Why the value returned by retInt()is not required to be cathed like
"int i=tf.retInt();"

class TestFunc{
public int retInt(){
return 7;
}
}
public class Test {
public static void main(String[] args) {
TestFunc tf=new TestFunc();
tf.retInt();
}
}


Akshay.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand "cathed", but invoking a method can stand alone as a statement. Any return value is just thrown away.
 
Akshay Bhatia
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I meant catched.

Akshay.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Mike stated, you do not have to "catch" (store) the return value from a function.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!