Q:

Is it necessary to close Scanner inside Block Lambda Expressions?

I'm new to Lambda Expressions in java and I'm not sure whether is it necessary to additionally close Scanner inside the Block Lambda Expressions:
public interface factorialInterface {
    int factorialMe (int n);
    }

import java.util.Scanner;
public class factorialDemo {
    public static void main(String args[]) {
        Scanner keyb = new Scanner (System.in);

        factorialInterface fact = (n) -> {
            int result = 1;

            for (int i = 1; i <= n; i++) {
                result = i * result;
            }
            keyb.close();  // <- not sure about this one.
            return result;
        };
        System.out.print("Pass value: ");
        System.out.println(fact.factorialMe(keyb.nextInt())); 
        System.out.println();

        keyb.close(); 

    }

}

If I won't close 'keyb' inside of this block Eclipse will inform me about the Resource Leak. Is it always recommended to close Scanner inside of the Lambda Block?
Thanks for help!

A:

You are not using keyb inside fact in any other way except closing it. It totally does not belong there. Calculation of a factorial of n is a pure function that only depends on n and nothing else.
This is likely a bug in Eclipse. Try moving the declaration of keyb closer to its usage, that is, right after print("Pass value: ").

