1

Is there any smart way to override Java method in Scala using eclipse?

I don't see in eclipse (Scala IDE) the option for 'Source' which I used to using for Java files (Source -> Override/ Implement method).

I tried other way typing def override exampleMethodand here I pressed Ctrl + Space. Ide correctly suggests the method from super class however when I accept suggestion I see only

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. That is not very convenient.

But maybe I could do it somehow better?

Łukasz Rzeszotarski
  • 5,791
  • 6
  • 37
  • 68
  • Have you tried specifying the superclass in the New Scala Class dialog box when creating the class initially? That should create method stubs for abstract methods to override, if the option is selected, although due to a bug that functionality was not present in certain versions of Scala IDE for Eclipse. – Robin Green Nov 28 '13 at 23:00
  • 1
    Hmmm... Generating stubs for not implemented methods doesn't work for me. My version 'Scala IDE build of Eclipse SDK Build id: 3.0.2-vfinal-20131028-1923-Typesafe'. Even if it would work still the problem is for methods to override. – Łukasz Rzeszotarski Nov 28 '13 at 23:15

1 Answers1

1

Generating stubs for overridden method in general is not currently supported in Scala IDE.

One solution is to use the new 'Java to Scala' plugin, which convert on the file Java code into Scala code. 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.

(obligatory) Also, we do accept code contributions for a more integrated solution.

skyluc
  • 640
  • 4
  • 6