I want to declare a variable with name 'type' in a Play/Scala application, since my data has this field name and I'm using JSON transforms. It just makes more sense.
Fortunately I could just rename the field, but still curious if there is a way to make the compiler ignore the type reserved word when declaring variables.
使用反引号:
var `type` = 42
def main(args: Array[String]): Unit = {
var `type`: String = "Hello World"
println(`type`)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.