使用Java中的参数和内部类调用scala抽象类

Jus*_*s12 3 java scala scala-java-interop

如果我定义一个Scala类:

 class X(i:Int) {
   println (i)
 }
Run Code Online (Sandbox Code Playgroud)

如何在Java代码中使用此类?

[编辑]实际上,我的问题稍微复杂一些

我有一个抽象的课

 abstract class X(i:Int) {
   println (i)
   def hello(s:String):Unit
 }
Run Code Online (Sandbox Code Playgroud)

我需要在Java代码中使用它.是否可以轻松完成?

[EDIT2]考虑以下代码

 object B {
    case class C(i:Int)
 }
 abstract class X(i:Int) {
   println (i)
   def hello(a:B.C):Unit
 }
Run Code Online (Sandbox Code Playgroud)

在这种情况下,以下java代码在Netbeans IDE中出错,但构建正常:

 public class Y extends X  {
    public void hello(B.C c) {
       System.out.println("here");
    }
    public Y(int i) {
       super(i);
    }
 }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

hello(B.C) in Y cannot override hello(B.C) in X; overridden method is static, final
Run Code Online (Sandbox Code Playgroud)

Netbeans 6.8,Scala 2.8.

截至目前,我认为唯一的解决方案是忽略NB错误.

这是一张显示我得到的确切错误的图片: 使用java中的scala代码的IDE错误

Kev*_*ght 7

生成的类的字节码 Java定义相同:

abstract class X implements scala.ScalaObject {
  public X(int i) {
    System.out.println(i);
  }

  public abstract void hello(String s);

  //possibly other fields/methods mixed-in from ScalaObject
}
Run Code Online (Sandbox Code Playgroud)

完全像对等Java一样使用它; 子类并提供该hello方法的具体实现.