https://kotlinlang.org logo
Title
d

darkmoon_uk

06/17/2017, 7:47 AM
Why does
Array
have an inline constructor; when the compiler says this is disallowed in my own code?
v

voddan

06/17/2017, 8:09 AM
darkmoon_uk: what constructor are you referring to?
(AFAIK
inline constructor
is not a thing)
d

darkmoon_uk

06/17/2017, 8:09 AM
Exactly my point...
but look at kotlin.Array
public inline constructor(size: Int, init: (Int) -> T)
v

voddan

06/17/2017, 8:10 AM
👀
d

darkmoon_uk

06/17/2017, 8:11 AM
And something about it is really ruining my day; something I thought would be easy... I want to create an Array<T> inside MyClass<T>'s initializer. It won't have it, because calling Array<T> it's insisting it be reified, and I can't have reified T inside a constructor!
I can pass in KClass, but that doesn't help with creating Array<T> either.
I can make a reified create() method in Companion class, but that requires I expose the Array<T> as part of MyClass's public constructor, which I don't want to do.
It looks like a bit of a hole in the language TBH
v

voddan

06/17/2017, 8:15 AM
Arrays ARE objects, bth.
inline
there is for the lambda performance
d

darkmoon_uk

06/17/2017, 8:18 AM
Hmm, I guess this is no more restrictive than Java, will have to consider using
Array<Any?>
and casting inside my class.
Thx.
v

voddan

06/17/2017, 8:35 AM
@darkmoon_uk I know I've mentioned it, but why would you use
Array
instead of
List
or
MutableList
? Their performance are exactly the same, but lists have normal generics
d

darkmoon_uk

06/17/2017, 8:44 AM
...with it's immediate, fixed size specification and initialization function, this is the exact API I would like to store image data.
I can recreate this for list but it will be extra work, it's a shame the generic behaviour of Array is peculiar. Especially when it's all just same-sized object pointers at the end of the day.
d

darkmoon_uk

06/17/2017, 1:11 PM
Shame, gratitude... thanks.
List fixes all 🙂
v

voddan

06/17/2017, 2:47 PM
Shame on us as a community, because those function are really tough to find without knowing they exist. We need new ideas for docs, and fast
r

radityagumay

06/17/2017, 11:09 PM
Actually inline for performance purpose and you can inline kind of tailrecursion for example
2
Kindly watch hadi hariri presentation about tailrecursion