Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to store a value from a method which is retuning a value in java?

Tags:

java

Let suppose I have a method

public int dummy(){
  return 1;
}

and if I call this method by

dummy();

not

int a  = dummy();

will it make any difference? why?

like image 753
Prakhar Khandelwal Avatar asked Jan 27 '23 01:01

Prakhar Khandelwal


1 Answers

No, it wouldn't make any difference. We call a ton of methods from the JDK ignoring their outputs - List's .remove(int index) removes the element at a given index, and returns what element was removed. It is normal to ignore it and move ahead.

like image 185
Prashant Pandey Avatar answered Jan 30 '23 02:01

Prashant Pandey