This is not compilable ```class CafHttpResult<T...
# compiler
e
This is not compilable
Copy code
class CafHttpResult<T> {
    var result: T = null
}
But I write
<T: Any>
for that. Was it always like this?
1
I also see many references by people about
Copy code
If we don't specify the upper bound, Kotlin will assume a default of Any?
p
Copy code
class CafHttpResult<T> {
     var result: T? = null
 }
e
I know the fix, I was surprised that I need to add
?
So I can define
CafHttpResult<Int?>
then it translates for me to
var result: Int??
p
T is a type parameter. Real type can be any of nullable or not nullable
Nullable type ? = Nullable type
f
I was surprised that I need to add
?
If
T
was
Int
(
CafHttpResult<Int>()
),
var result: T = null
would become
var result: Int = null
and that does not make sense. How would you expect it would work? 🤔
e
Also true
Oke, even the default upper bound is Any, the having
?
is definitely improvement
Thank you, people!
e
that's not the issue. the use site can choose the actual
T
, such as
CafHttpResult<Int?>()
which would be ok, or
CafHttpResult<Int>()
which would not, as Filip said
it's not like C++'s SFINAE where it's fine for parts of some templates to be invalid under some instantiations