https://kotlinlang.org logo
Title
s

Smallville7123

04/09/2019, 7:00 AM
there are probably more primitive types that i am missing
d

diesieben07

04/09/2019, 7:01 AM
String
is also not a primitive type.
Like was said before: what are you trying to accomplish here?
s

Smallville7123

04/09/2019, 7:04 AM
oh it isnt
well at least it initializes it to ""
k

karelpeeters

04/09/2019, 7:12 AM
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

Smallville7123

04/09/2019, 8:07 AM
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
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()
}
ff[0] = 5
ff[0] = null
d

diesieben07

04/09/2019, 8:18 AM
That code does not compile.
Unless you are using
java.util.AbstractList
. In that case: yes, java types are not null-safe.
s

Smallville7123

04/09/2019, 8:35 AM
ok, does kotlin have its own version of AbstractList?
k

karelpeeters

04/09/2019, 4:51 PM
You should never be using
AbstractList
(neither in Java nor in Kotlin), use the
List
or
MutableList
interface.
s

Smallville7123

04/09/2019, 11:43 PM
I'll try to use those instead