I'm still trying to come to grips with nullable types and generics. Let's say I want to create a function that takes a nullable type, and returns a non-null version of that say type. For simplicity, something like:
fun toNonNull<T>(t: T): T { if (t == null) throw NullPointerException() return t!! }
Obviously, this doesn’t work, but I’m not sure how I would write something that would achieve the same effect. How do I write a generic function that accepts a nullable version of a type but returns the non-nullable version of that same type.