Not enough information to infer type variable T

I’m using a library function call for which the return type is Any. So, in this case the actual return type is an array of doubles. Actually, what’s returned is {double[1]@ …} so it is (I think) a two dimensional array of doubles. So, I want to extract a single array of doubles or Doubles that is, I just want to get at the numbers. This is proving to be a huge hassle. So much of Kotlin ultimately ends up being a hassle. Is there a quick and dirty way to convert/cast this Any type to an array of doubles (DoubleArray) or Doubles (Array)? I don’t care about jumping through hoops to make the code bullet proof as it is just a one up analysis that will never leave my computer.
Thanks.

From your description it is hard to understand what you need exactly. Casting to array of doubles is as simple as: obj as DoubleArray.

Nope. code snippit,
val data: Any
val data2: DoubleArray

data = dataset.getData()
data2 = data as DoubleArray

run result,
Got,
Exception in thread “main” java.lang.ClassCastException: class [[D cannot be cast to class [D ([[D and [D are in module java.base of loader ‘bootstrap’)
at io.jhdf.examples.MainKt.main(Main.kt:23)
at io.jhdf.examples.MainKt.main(Main.kt)

In this case: as Array<DoubleArray>.

1 Like

Thanks. That worked.