- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
EnumClass.values()
在Kotlin中如何工作?
我的意思是,它将每次创建新的Array
,还是被静态评估为惰性,还是其他?
最佳答案
虽然不是100%肯定,但我假设Enum.values()
方法是由编译器生成的: Kotlin (以及 Java ):
The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all of the values of the enum in the order they are declared. This method is commonly used in combination with the for-each construct to iterate over the values of an enum type.
/**
* Returns an array containing the constants of this enum
* type, in the order they're declared. This method may be
* used to iterate over the constants as follows:
*
* for(E c : E.values())
* System.out.println(c);
*
* @return an array containing the constants of this enum
* type, in the order they're declared
*/
public static E[] values();
enum class MyEnum { CAT, DOG }
val a = MyEnum.values()
val b = MyEnum.values()
println("${a === b}") // >>> false
a[0] = MyEnum.DOG
println(a.joinToString()) // >>> [DOG, DOG]
println(MyEnum.values().joinToString()) // >>> [CAT, DOG]
关于kotlin - EnumClass.values()在Kotlin中如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49753250/
EnumClass.values()在Kotlin中如何工作? 我的意思是,它将每次创建新的Array,还是被静态评估为惰性,还是其他? 最佳答案 虽然不是100%肯定,但我假设Enum.values
如果你有一个 Java enum 和一个枚举类型的变量,如下所示: public enum Something { VAL1, VAL2, VAL3 } public Somethi
我是一名优秀的程序员,十分优秀!