I have a program in java, in which I have to get user input, however, I only need to get the user input once, after that, I do not need a scanner anymore. Doing the following:
int userInput = new Scanner(System.in).nextInt();
Gives me a Resource Leak warning, saying that <unassigned closeable value> is never closed
.
Is there another way I can use a Scanner only once, and get rid of it afterwards so there's no Resource Leak? Maybe something similar to C#'s using
statement.