Skip to content

Utilities

Roman Makeev edited this page Nov 17, 2022 · 2 revisions

This page contains basic utilities of AstraLibs

Enums

With AstraLibs you can easily iterate through enums

// ktx_core_ext.kt
enum class MyEnum{
    FIRST,SECOND,THIRD
}
fun nextEnum(){
    val myEnumInstance = MyEnum.FIRST
    myEnumInstance.next() // MyEnum.Second 
    myEnumInstance.addIndex(2) // MyEnum.Third
    valueOfOrNull<MyEnum>(FIRST) // MyEnum.First
}

ReflectionUtil

// ReflectionUtil.kt
class MyClass(var customValue: Int)

ReflectionUtil.getDeclaredField(MyClass::class.java,"customValue")
val myClassInstance = MyClass(0)
ReflectionUtil.setDeclaredField(MyClass::class.java,myClassInstance, "customValue", 10)
Clone this wiki locally