1

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

The constructor is declared in that way:

public <SUBCLASS extends Node> NodeDock(Parent<? super Node> parent, Class<SUBCLASS> cls, LookupCriteria<SUBCLASS>[] criteria) {
   this(parent, cls, 0, criteria);
}

So if i want to use it:

val task = new NodeDock(scene.asParent(), classOf[FXTaskStackElement].asInstanceOf[Class[_]], new LookupCriteria[FXTaskStackElement]() {...}

Scala is giving me always an error that he cannot find the appropriate constrcutor with these parameters. So how can i get the SUBCLASS of FXTaskStackElement for the LookupCriteria?

Edit: In Java i would call this constrcutor like that, which works fine:

task = new NodeDock(scene.asParent(), FXTaskStackElement.class, new LookupCriteria<FXTaskStackElement>() {...})

1 Answer 1

1

Why are you using classOf[FXTaskStackElement].asInstanceOf[Class[_]] instead of just classOf[FXTaskStackElement]? Since your second argument is a Class[_], there is no suitable SUBCLASS.

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

1 Comment

Oh my god, i have searched for the wrong problem... thank you, that was the point, i had to use .asInstanceOf for another constructor without it whould have not worked. So i thought that i have to use it with this constructor as well, but it works now with: val task = new NodeDock(scene.asParent(), classOf[FXTaskStackElement], new LookupCriteria[FXTaskStackElement]() {...}

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.