【问题标题】:How to name a method parameter with an identifier equaled ot Scala language keyword? [duplicate]如何使用等于 Scala 语言关键字的标识符命名方法参数? [复制]
【发布时间】:2013-11-14 04:32:15
【问题描述】:

所以我尝试声明这个简单的案例类

case class Association(id: Option[Long], type: String, name: String, description: Option[String], uri: URI, additonalInfo: String){

}

但它不会与此消息一起编译:

- identifier expected but    'type' found.

这当然是因为“type”是一个保留的 Scala 关键字。由于某些原因,我认为我可以通过提供 'type (Symbol) 来解决这个问题,但它仍然无法编译。

那么我如何才能真正将我的参数标记为“类型”? 请不要让我失望,告诉我这不能在 Scala 中完成 :)

【问题讨论】:

    标签: scala


    【解决方案1】:

    只使用粗引号:

    case class Association(id: Option[Long], `type`: String, name: String, description: Option[String], uri: URI, additonalInfo: String)
    

    【讨论】:

    • 非常感谢,@om-nom-nom。那行得通:)
    • @AlexanderArendar:您可以接受此答案以标记您的问题已解决。
    猜你喜欢
    • 2011-09-30
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-30
    • 2011-04-09
    相关资源
    最近更新 更多