I have created a project that uses scala that has some abstract classes definitions such as:
abstract class A(n: String) {
require(n!= null)
val name = n
var inputs: List[Input[_]]
var outputs: List[Output[_]]
}
abstract class B(n: String) extends A(n){
def act
def isValid : Boolean
def getCs : List[C[_]]
}
abstract class C[Type]{
var value: Type
}
Now I want to use that project in Java. I have imported scala lib in a new project and added scala project in the build path. I am using eclipse.
However, when I try to do this:
public class CoolClass extends B {
public CoolClass(){ }
}
EDIT:
I have some problems using this in Java that raised me some doubts. Let me enumerate them:
- Can I use Lists from Scala or that gives errors in Java?
- Why vars from A aren’t recognized in classes that extend B in Java?
- How can I declare
getCsso it provides an interface withList<C>instead ofList<C<?>>?
I’m just assuming, that you implemented all the methods you define in you
class Balso in your javaclass CoolClass. What is missing here is the call toB‘s constructor, as the error message says.There is no default constructor defined on your
class B, so you have to explicitly call the one that is defined, which isB(n: String).edit:
1: You can use anything you want on both sides. Though the method names may be different in some special cases like anything that includes special chars in scala.
2: They are recognized, though they are not fields, but methods in the java code. You can access them with
this.inputs()andthis.outputs()3: Try
def getCs[C]: List[C]