Skip to content

Instantly share code, notes, and snippets.

@Jire
Created November 30, 2015 19:55
Show Gist options
  • Save Jire/63da3cf482bb9f5d4749 to your computer and use it in GitHub Desktop.
Save Jire/63da3cf482bb9f5d4749 to your computer and use it in GitHub Desktop.
val TYPE_TO_BYTES = mapOf(Boolean::class.java to 1, Byte::class.java to 1,
Short::class.java to 2, Int::class.java to 4, Long::class.java to 8,
Float::class.java to 4, Double::class.java to 8)
inline fun <reified T: Any> read(address: Long): T {
val type = T::class
if (Int::class.java == type.java)
println("Nice! :)")
else if (Int::class == type) // would be nicer if this was possible
println("Nicer!")
if (!TYPE_TO_BYTES.contains(type.java))
println("Why not!?!?! ${type.java}")
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment