最后活跃于 1725104485

rcaldous's Avatar rcaldous 修订了这个 Gist 1725104485. 跳至此修订

1 file changed, 0 insertions, 0 deletions

EnumString.Kt 重命名为 EnumString.kt

File renamed without changes

rcaldous's Avatar rcaldous 修订了这个 Gist 1725104476. 跳至此修订

1 file changed, 8 insertions

EnumString.Kt(file created)

@@ -0,0 +1,8 @@
1 + // https://stackoverflow.com/questions/28548015/how-do-i-create-an-enum-from-a-string-in-kotlin
2 + inline fun <reified T : Enum<T>> valueOf(type: String): T? {
3 + return try {
4 + java.lang.Enum.valueOf(T::class.java, type)
5 + } catch (e: Exception) {
6 + null
7 + }
8 + }
更新 更早