简体   繁体   English

使用eclipse覆盖Scala中的Java方法

[英]Overriding Java method in Scala using eclipse

Is there any smart way to override Java method in Scala using eclipse? 有什么聪明的方法可以使用eclipse覆盖Scala中的Java方法?

I don't see in eclipse (Scala IDE) the option for 'Source' which I used to using for Java files (Source -> Override/ Implement method). 我在Eclipse(Scala IDE)中没有看到我以前用于Java文件的“源”选项(“源”->“覆盖/实现”方法)。

I tried other way typing def override exampleMethod and here I pressed Ctrl + Space . 我尝试了其他方式键入def override exampleMethod然后在这里按Ctrl + Space Ide correctly suggests the method from super class however when I accept suggestion I see only ide正确地建议了超类的方法,但是当我接受建议时,我只会看到

exampleMethod(param1, param2... etc.) // without arguments types - like a method call 

Method which I wanted to override have 7 parameters and foreach of them I had to check its type. 我想覆盖的方法有7个参数,对于每个参数,我必须检查其类型。 That is not very convenient. 那不是很方便。

But maybe I could do it somehow better? 但是也许我可以做得更好?

Generating stubs for overridden method in general is not currently supported in Scala IDE. 通常,Scala IDE当前不支持为覆盖的方法生成存根。

One solution is to use the new 'Java to Scala' plugin, which convert on the file Java code into Scala code. 一种解决方案是使用新的“ Java to Scala”插件,该插件将文件Java代码转换为Scala代码。 It works well for abstract method definitions. 它适用于抽象方法定义。 For concrete methods, the trick I found to not convert the whole body, is: 对于具体方法,我发现不转换整个身体的技巧是:

  • copy the method signature 复制方法签名
  • paste it 贴上
  • add a ; 添加;
  • cut the text 剪下文字
  • paste it using the conversion 使用转换粘贴

The plugin is available from the Scala IDE update site. 可从Scala IDE更新站点获得该插件。

(obligatory) Also, we do accept code contributions for a more integrated solution. (强制性)而且,我们确实接受代码贡献以提供更集成的解决方案。

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

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