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.
Java does not support call by reference because in call by reference we need to pass the address and address are stored in pointers n java does not support pointers and it is because pointers breaks the security. Java is always pass-by-value.
Java is Pass by Value and Not Pass by Reference.
Object references are passed by value The reason is that Java object variables are simply references that point to real objects in the memory heap. Therefore, even though Java passes parameters to methods by value, if the variable points to an object reference, the real object will also be changed.
Java is always pass by value and not pass by reference .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With