Resource leak: 'in' is never closed

2019-01-03 08:39发布

Why does Eclipse give me the warming "Resource leak: 'in' is never closed" in the following code?

public void readShapeData() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the width of the Rectangle: ");
        width = in.nextDouble();
        System.out.println("Enter the height of the Rectangle: ");
        height = in.nextDouble();

13条回答
相关推荐>>
2楼-- · 2019-01-03 09:33

Because you don't close your Scanner

in.close();
查看更多
登录 后发表回答