Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Last active November 11, 2022 07:38
Show Gist options
  • Save michalbcz/6030c7885f7d967f57fcee5d8e1f2811 to your computer and use it in GitHub Desktop.
Save michalbcz/6030c7885f7d967f57fcee5d8e1f2811 to your computer and use it in GitHub Desktop.
groovy: what happened when you use backslash as last character in "Slashy string"
/*
Example what happened when you use backslash in Slashy string (https://groovy-lang.org/syntax.html#_slashy_string)
Note: there is a note that you are not supposed to do that in https://groovy-lang.org/syntax.html#_special_cases
"A consequence of slash escaping is that a slashy string can’t end with a backslash"
*/
import groovy.io.*
// def dir = new File(/C:\Users/) // WORKS (removed last slash)
// def dir = new File("C:\\Users\\") // WORKS
// def dir = new File("C:\\Users") // WORKS
// from statement below any GString with interpolation or comments doesn't work (ie. cannot be compiled)
def dir = new File(/C:\Users\/)
def expressionWorks = 1+1
println expressionWorks
println "GString without interpolation works"
println 'String works'
dir.eachFile({ file ->
"expression below is not working, remove it (commenting doesn't work either) and it starts to work"
println "${file}"
"working expressions"
println file
println "file"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment