Created
May 3, 2020 22:03
-
-
Save PetkevichPavel/325bbc8d397070310cc550fef1bca5bc to your computer and use it in GitHub Desktop.
SharedPreferences under Delegated properties - generic type class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Generic<T : Any>(val c: Class<T>) { | |
companion object { | |
/** | |
* Returns generic's argument class. | |
*/ | |
inline operator fun <reified T : Any> invoke() = Generic(T::class.java) | |
} | |
/** | |
* Check if value is instance of desired class. | |
*/ | |
fun checkType(t: Any) = c.isAssignableFrom(t.javaClass) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment