0

How can I extends a Java class that expects a Map<?, ?> in its constructor in Scala?

The Java class looks like

public class MyJavaClass {

  private final Map<String, ?> originals;

  public MyJavaClass(Map<?, ?> originals,  Map<String, ?> configProviderProps, boolean doLog) { ... }

  public MyJavaClass(Map<?, ?> originals) {
    this(originals, Collections.emptyMap(), true);
  }
}

In Scala I was trying to do something like below but my IDE tells my that it "cannot resolve overloaded Constructor":

class myScalaClass[K <: AnyRef, V <: AnyRef](origi: Map[K, V]) extends MyJavaClass(origi) { ... }

Also tried to replace AnyRef with java.lang.Object without success. I am using Java 8 and Scala 2.12.11.

2
  • Would wildcards work for you or do you have to know the types K and V? Also, I don't think you need an upper bound at all Commented May 24, 2020 at 18:56
  • Actually, scratch that, you don't need wildcards Commented May 24, 2020 at 19:08

1 Answer 1

3

Try

class myScalaClass(origi: java.util.Map[_, _]) extends MyJavaClass(origi) {  }
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.