Skip to content

Instantly share code, notes, and snippets.

@PetkevichPavel
Created May 3, 2020 22:03
Show Gist options
  • Save PetkevichPavel/325bbc8d397070310cc550fef1bca5bc to your computer and use it in GitHub Desktop.
Save PetkevichPavel/325bbc8d397070310cc550fef1bca5bc to your computer and use it in GitHub Desktop.
SharedPreferences under Delegated properties - generic type class.
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