I have an API with a signature in Java that return public Foo<?> getFoo()
Then when I try to consume that API from Scala, is complaining about ?.
val fooValue:Foo[_] = API.getFoo()
I also try with Any
val fooValue:Foo[Any] = API.getFoo()
Any idea how can I set the question mark type in Scala
The following code compiles
Foo.java
public class Foo<T> {
}
API.java
public class API {
public static Foo<?> getFoo() {
return null;
}
}
App.scala
object App {
val fooValue: Foo[_] = API.getFoo()
}
Foo[?] is not valid Java syntax.
If the method is public static Foo<?> getFoo() you can call it like API.getFoo(). If it's public Foo<?> getFoo() you can call it like new API().getFoo().
Question mark (?) in Java corresponds to underscore (_) in Scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With