What do you think about the following: I have a cl...
# announcements
k
What do you think about the following: I have a class
MyList<T>
that inherits from
java.util.AbstractList<T>
. Because that's a java class, instances of my class always appeared as
MyList<T!>
and
myList.get(0)
returned an instance of
T!
even when I declared it as
MyList<T>()
. To fix this, I also let my class implement
kotlin.collections.List<T>
, now
myList.get(0)
returns instances of
T
which is great. What's weird, however, I that I still can invoke
myList.indexOf(null)
. Also, I can call
myList.add(null)
which will crash at runtime (
AbstractList
implements it to throw). I can kinda understand this behavior because the methods are present in `MyList`'s super class hierarchy. Still, it makes dealing with my class a little bit dangerous. I guess my questions comes down to, whether the stdlib should provide an abstract class that you extend if you want to have your own
List
type.