views:

107

answers:

2

For example I have following Java inteface

public interface Test<T,M> {
       public M get(T t);
}

if I whant create ananymoys class in java with this interface

val t = new Test[Int,Boolean](){
     def get(t: Boolean) = 0
}

I have following error

Scala.scala:15: error: scal.test.example.Test does not take type parameters val t = new Test[Int,Boolean](){

+4  A: 

Enclosing your Scala code in an object for separate compilation and correcting the order of the type parameters:

object TestI {
    val t = new Test[Boolean,Int]() {
        def get(t: Boolean) = 0
    }
}

... I do not get any compilation errors.

Randall Schulz
I tried this and get the same error. I use maven for compilation with scala compile plugin with version 2.6.1 and scala 2.8
Alexander Kuznetsov
I suspect either your Java interface is not in the same package as your Scala class, you failed to import that interface, Maven isn't compiling the Java first, the Java-generated `.class` files aren't in the class-path during Scala compilation or some combination thereof.
Randall Schulz
This is not a problem becouse the following code works fine val t = new Test() { def get(t: Any) = null } That is you version of scala?
Alexander Kuznetsov
I should have noticed that your diagnostic was not about an undefined `Test`, but rather about a `Test` that was being used in a manner not consistent with its definition.
Randall Schulz
+1  A: 

It was old version of scala 2.6.1. It was installed by default from maven archity for scala projects. Now I upgraded version to 2.8.0 and problem was solved. For old version your need to scpecify the version of java.

Alexander Kuznetsov