3

I was thinking to return a map with several directories list. But the very first caused a warning for me:

def enlistFiles() {

    return
        [downloadFolder: downloadFolder.listFiles( new FileFilter() {
            @Override
            boolean accept(File file) {
                return !file.isDirectory()
            }
        })]

}

"Code unreachable"

Why?

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 9
    Because of optional semicolons, the newline at the `return` line is interpreted as an end of statement. So you have 2 statements : one `return`, then an unreachable map. – melix Dec 08 '15 at 09:01
  • Shame on my head, thanks! :) – Dims Dec 08 '15 at 09:42
  • 1
    @melix you should post that as an answer. [Damn](http://robertnyman.com/2008/10/16/beware-of-javascript-semicolon-insertion/)! – Will Dec 09 '15 at 19:55

1 Answers1

1

Anything below line 3 will not be executed. The return key word should not be followed by a line break. Your code should be:

def enlistFiles() {
    return [downloadFolder: downloadFolder.listFiles( new FileFilter() {
            @Override
            boolean accept(File file) {
                return !file.isDirectory()
            }
        })]

}
Viorel Florian
  • 594
  • 9
  • 29