I'm working on a project which has both scala and java code. I want to use a class written in scala in java code. Problem I'm having is that scala class has some self type dependencies. I don't know how to give them when creating new instance of that class from java.
trait Deps1 {
def dep1 = println("dep1")
}
trait Deps2 {
def dep2 = println("dep2")
}
class TestClass {
this: Deps1 with Deps2 =>
def test = {
dep1
dep2
}
}
In scala if I'm to create instance of TestClass
I can use new TestClass with Deps1 with Deps2
but I don't know how to do that in java code.
I'm using scala 2.9.2. Can anyone help me on this?
Method 1:
Creating class with all the dependencies in scala and using that (as mentioned by Rex) is the easiest I think.
Method 2:
In addition to that we can implement class directly in java as follows and use it.
class TestClassWithDeps extends TestClass implements Deps1, Deps2 { public void dep1() { Deps1$class.dep1(this); } public void dep2() { Deps2$class.dep2(this); } } – Chathurika Sandarenu Jul 12 '12 at 07:10