Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin unresolved reference linkedListOf

Following this post http://obviam.net/index.php/libgdx-and-kotlin/ I created a project, and edited using Atom. It compiles, and runs on an android device. I want to convert to AndroidStudio for better tooling.

I'm using AndroidStudio 1.5.1, and it says I have the latest version of the kotlin plugin. I created a new project using the LibGDX setup program, imported into AdroidStudio, converted the main class to kotlin, everything works. Then I pasted in my existing my code, and when I build, this line:

val bullets:MutableList<NewBullet> = linkedListOf() 

gets this error:

Error:(19, 42) Unresolved reference: linkedListOf

When I select Tools -> Kotlin -> Configure it says 'All modules with Kotlin files are configured'.

I've also tried importing the existing project into AndroidStudio, and the result is the same issue.

like image 743
user2241515 Avatar asked Dec 08 '25 09:12

user2241515


1 Answers

As said in the change log of Kotlin 1.0 RC, linkedListOf has been deprecated and is not available now. The article you referenced uses Kotlin 1.0 Beta, which is older.

To create a LinkedList<T> from varargs, you can pass a listOf(...) to the constructor:

val bullets: MutableList<SomeType> = LinkedList(listOf(item1, item2))

or write your own linkedListOf:

fun <T> linkedListOf(vararg items: T) = LinkedList<T>().apply { 
    for (i in items) { add(i) }
}
like image 149
hotkey Avatar answered Dec 11 '25 09:12

hotkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!