there are probably more primitive types that i am ...
# getting-started
s
there are probably more primitive types that i am missing
d
String
is also not a primitive type.
Like was said before: what are you trying to accomplish here?
s
oh it isnt
well at least it initializes it to ""
k
You're also missing every possible type anyone ever declares without giving it a default no-args constructor, which is the real flaw with your approach.
s
such as if someone declares
class a(v : Int)
?
also how can i check if a type is nullable
as i just discovered i can explicitly set a non nullable type as null
Copy code
fun <E> makeNull(v: AbstractList<E>) {
    v[0] = null
}

fun ret() {
    val ff = arrayListOf<Int>()
    ff.add(5)
    println("ff[0] = ${ff[0]}")
    makeNull(ff)
    println("ff[0] = ${ff[0]}")
    abort()
}
Copy code
ff[0] = 5
ff[0] = null
d
That code does not compile.
Unless you are using
java.util.AbstractList
. In that case: yes, java types are not null-safe.
s
ok, does kotlin have its own version of AbstractList?
k
You should never be using
AbstractList
(neither in Java nor in Kotlin), use the
List
or
MutableList
interface.
s
I'll try to use those instead