سؤال

I have a java interface with a method declared like this String type();. I want to implement it in a scala class, so I would like to write:

override def type = { ... }

But apparently its a reserved keyword in scala, so the compiler is complaining:

 identifier expected but 'type' found.

How is it possible to implement it? Is there a solution without having to change the Java interface?

هل كانت مفيدة؟

المحلول

You can use backticks to overcome the issue of reserved words:

override def `type` = { ... }

See: Scala Interoperability FAQs

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top