I know about https://www.javadoc.io/doc/io.vavr/vavr/latest/io/vavr/Value.html#toJavaArray but it's deprecated. Is there a non-deprecated method that can be used?
Out of the three toJavaArray
variants, only the toJavaArray(Class)
variant is deprecated directly, the other two are marked as deprecated because the Value
class itself is deprecated. The generated javadoc is not very helpful in distinguishing between the two, unfortunately, but you can check the source code directly. This picture is probably a more precise representation of the current state:
Value
is deprecated in favor of io.vavr.Iterable
. This new interface is an extension of the java.lang.Iterable
type, that differs mainly in that it returns an io.vavr.collection.Iterator
instead of a simple java.util.Iterator
. io.vavr.collection.Iterator
extends Value
, and I expect that after the removal of the Value
interface, all methods which are not explicitly deprecated in the Value
interface will be moved to io.vavr.collection.Iterator
.
Out of the two not explicitly deprecated toJavaArray
methods I would use the T[] toJavaArray(IntFunction<T[]> arrayFactory)
variant – which was one of my contributions to the vavr project –, as it returns a typed array of the correct type instead of an Object[]
.
To sum it up, instead of using vavrValue.toJavaArray()
, I would use vavrValue.iterator().toJavaArray(SomeType[]::new)
.