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

Prakhar Khandelwal :

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?

Prashant Pandey :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=125261&siteId=1