How to override type() java interface method in a scala class
-
02-07-2021 - |
سؤال
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` = { ... }
لا تنتمي إلى StackOverflow