Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有这样声明的方法的 java 接口String type();。我想在 scala 类中实现它,所以我想写:
String type();
override def type = { ... }
但显然它是scala中的保留关键字,所以编译器抱怨:
identifier expected but 'type' found.
怎么可能实现它?是否有无需更改 Java 接口的解决方案?
您可以使用反引号来克服保留字的问题:
override def `type` = { ... }
请参阅:Scala 互操作性常见问题解答