Home > OS >  Java/Scala Required: Iterable[_ <: Float], found: Iterable[Float]
Java/Scala Required: Iterable[_ <: Float], found: Iterable[Float]

Time:12-08

I have a protobuf method in Java with definition

public Builder addAllTensor(
          Iterable<? extends Float> values)

I call the method in Scala with a val a: ArrayList[Float], its ok during code check, but error during build

type mismatch;
 found   : java.util.ArrayList[scala.Float]
 required: Iterable[_ <: java.lang.Float]

But calling it with a.toIterable it raises error in code check(in IntelliJ IDEA)

Required: Iterable[_ <: Float], found: Iterable[Float] 

(How could this be type mismatch...) Just wonder why...

CodePudding user response:

The issue is with the scala.Float versus Java's Float.

Automatic conversion doesn't happen inside collections, you have to create somehow a collection of Java's Float.

  • Related