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](){

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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
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.
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?
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.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.