I'd like to do the following: Given a Java Class A
, which is part of a Java only project, I'd like to write an accompanying object to it in a separate file, so that scala code can use the A()
syntax for the apply
method. Is there a way to do this? I've tried the following:
// in A.java
public class A{
private final int i;
public A(int i){
this.i = i;
}
}
// In a separate file A$.java in the same package:
public class A${
public static A apply(int 3){ return new A(3);}
}
//Scala code, in S.sca
class S {
val a = A(42) //Error: object A is not a value
}
Writing an object
A directly in Scala doesn't work either. Is there a way to achieve this, passing some args to the compiler or so?