To get around the skipping nextLine() issue, and to make the code cleaner, have I a couple of times used the following approach:
private String getInput() {
return new Scanner(System.in).nextLine();
}
This have not been any production code, just small projects, so I haven't cared much if this could give performance issues since I found the approach very convenient. I really like to use this method for all inputs and parse the return value.
To the question - is this a very bad practice? I does not feel good to not close the Scanner, but since the object gets out of reach, have I been thinking that the Scanner object should be garbage collected and therefore also closed. How does the gc handle this?