Is it good practice to create an unused reference to the value returned by a called method?

coding-style, java

Solution

It could point to the ambivalence of methods in Java. You can use this method like this

String junk = in.nextLine();

or that

in.nextLine();

Maybe your teacher will emphasize on a "function" rather to a "procedure" (void return type). If you assign a value the reader knows you are using a method that returns a value.

I don't see any advantage while you are using modern IDEs.

Problem

I have a friend whose teacher considers this good practice: ``` public void enterAnythingToContinue(){ String junk = in.nextLine(); } ``` I googled this, but didn't find an explanation for it, though as expected there were other users of this method; mainly teachers. Could it be that it doesn't matter if you do it or not, and that it's just a matter of clarity and pedagogy? Even if you don't have a definite answer, any input is appreciated.

Original source