https://kotlinlang.org logo
#announcements
Title
# announcements
a

Andreas Sinz

10/13/2017, 10:12 AM
@robstoll what are you trying to achieve?
r

robstoll

10/13/2017, 11:08 AM
I have two functions, one expects T (which is defined as T: Any?) and another can only work for T without nullable. Currently the second has a null check in it and calls other methods which have to do the null check as well, which call other methods which have to do the null-check as well etc. etc. I would like to specify that the method expects T2: T but without nullable. I have a solution like this: class A<T2 : Any, T: T2?> where I am using T2 for the second method. But the additional type parameter seems so unnecessary
a

Andreas Sinz

10/13/2017, 12:53 PM
@robstoll are those methods in the same class and you have full control over your class?
r

robstoll

10/13/2017, 1:19 PM
@Andreas Sinz I have somewhat full control, but for simplicity we can say I have full control
a

Andreas Sinz

10/13/2017, 2:17 PM
@robstollthen the following should work just fine:
Copy code
class A<T: Any> {
    fun aNullable(t: T?) { } //*t* is nullabe here

    fun aNotNullable(t: T) { } //*t* is NOT nullable here
}