0

I want to write a method like this: public void print(Scanner scan),

and I want to use the try with resource to enclose scan in order to have it closed automatically. However, I can't write this: try(scan)

How come I am able to write: try(Scan scan = new Scanner()), but I can't just put in the scan variable from my method parameter in order to get the benefit from try with resource?

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
Thuy
  • 1,493
  • 1
  • 11
  • 11
  • 4
    What language are you using? – APerson Oct 24 '14 at 02:08
  • possible duplicate of [Why is declaration required in Java's try-with-resource](http://stackoverflow.com/questions/13836486/why-is-declaration-required-in-javas-try-with-resource) – PM 77-1 Oct 24 '14 at 02:20

0 Answers0