Yeah you don't have to get the return value. Sometimes, you don't care about the return value. For example, if you are reading a file line by line, and you want to skip the first 3 lines, you can call readLine() 3 times and not care about the return value
You can do this too, and I agree it looks bizzarre. I don't like doing it because it just makes it harder to read. THis is equivalent of
but it looks like it should do something like
which doesn't make sense in Java.. but this what my brain reads it as
Also: when you put your code into an IDE, you may find it gives you warnings when your code ignores the value returned by a method. This can occasionally be useful, by pointing out cases where you aren't using the method right or you didn't declare it right, but usually people know what they are doing (as in Jayesh's example) when they write code which ignores a returned value.
posted 6 years ago
Thank you all for the insight. Definately challenging to interpret as a newcomer. And they dont make it easy