The Java toArray method you are calling returns type Object[] which in Kotlin is Any[]. The problem is that the CycleArray constructor call is expecting the type T.
The List interface provides another toArray which accepts an initialised array of the expected type in order to determine the correct return type. This however will not work with a generic type as the type needs to be known at compile time. There is a particular way around this kind of problem in koltin which is to use a reified type:
inline fun <reified T> cycle(vararg idxs : Int) : CycleArray<T> {
val ret = elems.sliceArray(1 until elems.size).toCollection(ArrayList())
ret.add(0, elems[elems.size - 1])
return CycleArray<T>(ret.toArray(arrayOf<T>()))
}
This is not entirely suited to your situation however, because the class is generic, not the method. The downside of doing this is that you will have to specify the type when calling the method:
val obj = CycleArray<Int>(arrayOf(1, 2, 3))
val result = obj.cycle<Int>()
This is most certainly not ideal but will work. Otherwise you should rethink the design. Is it absolutely necessary that CycleArray accepts an Array as its argument? If not, opt for a List to begin with.