2

I want to use a Jar in Scala, that is written in Java.

There are classes, that have multiple constructores, for example:

public LabeledDock(Parent<? super Labeled> parent, int index, Class<?> subtype){}

and

public LabeledDock(Parent<? super Labeled> parent, Class<?> subtype)

So the first constructor has 3 inputs, the second only 2 inputs.

If i want to use these constructors in Scala in that way:

val button = new LabeledDock(scene.asParent(), classOf[Button])

Scala tells me that "ambiguous reference to overloaded definition"

If i use

val button = new LabeledDock(scene.asParent(), 0, classOf[Button])

all works fine. So i think with the first variable declaration Scala doesn't know which constructor he should use, because they are similar to each other. How can i use the constructor with only 2 inputs instead of adding the third input.

Thanks for your help!

3
  • Are there any more constructors for LabeledDock? Commented Aug 20, 2013 at 14:55
  • Yes, there are several more constructors. The problem always happened if i use a constructor that has only 2 parameters and is similar to another constructor (regarding to the input parameters) Commented Aug 20, 2013 at 15:01
  • Can you give a complete list of the constructors? Commented Aug 20, 2013 at 15:38

1 Answer 1

0

Now, with the help from a workmate, i have solved that problem.

Instead of

classOf[Button]

i have to use

classOf[Button].asInstanceOf[Class[_]]

With this it works fine.

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

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.