EnumString.Kt
                        
                             · 275 B · Text
                        
                    
                    
                      
                        原始文件
                      
                    
                      
                    
                        
                          
                        
                    
                    
                
                
                
            // https://stackoverflow.com/questions/28548015/how-do-i-create-an-enum-from-a-string-in-kotlin
inline fun <reified T : Enum<T>> valueOf(type: String): T? {
    return try {
        java.lang.Enum.valueOf(T::class.java, type)
    } catch (e: Exception) {
        null
    }
}
                | 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 | } |