Enumeration.asSequence所在位置是kotlin.sequences / java.util.Enumeration.asSequence,其相关用法介绍如下。

用法:

fun <T> Enumeration<T>.asSequence(): Sequence<T>

创建一个从该枚举返回所有值的序列。该序列被限制为仅迭代一次。

例子:

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val numbers = java.util.Hashtable<String, Int>()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.put("three", 3)

// when you have an Enumeration from some old code
val enumeration: java.util.Enumeration<String> = numbers.keys()

// you can wrap it in a sequence and transform further with sequence operations
val sequence = enumeration.asSequence().sorted()
println(sequence.toList()) // [one, three, two]

// the resulting sequence is one-shot
// sequence.toList() //  will fail
//sampleEnd
}

输出:

[one, three, two]