eclipse result: Resource leak: 'variable' is never closed | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

eclipse result: Resource leak: 'variable' is never closed

import java.util.Scanner; class HelloWorld2 { public static void main(String[ ] args) { Scanner variable = new Scanner(System.in); System.out.println(variable.nextLine()); } } //eclipse result: Resource leak: 'variable' is never closed

16th Mar 2019, 12:34 AM
mokim
mokim - avatar
1 ответ
+ 7
add variable.close(); Closing your Scanner means you cut the connection to the keyboard or in other words: your program is not waiting for user input anymore. https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html Most of the IDE's closes the Scanner if you don't use the close method. But I'm not sure what will happen if you have not closed the scanner in an executable Java program.
16th Mar 2019, 1:24 AM
Denise Roßberg
Denise Roßberg - avatar