简体   繁体   English

如何在 Play/Scala 中声明一个名为“type”的变量?

[英]How to declare a variable named 'type' in Play/Scala?

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.我想在 Play/Scala 应用程序中声明一个名为“type”的变量,因为我的数据有这个字段名称并且我正在使用 JSON 转换。 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`)

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM