Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Kotlin for Java Developers Hello Kotlin! Using the Deck

why my cards.toMutableList() is unsolved reference

class Deck{

val cards = Array(52, { Card(it % 13, getSuit(it)) })

var cardsInDeck = MutableList<Card> = cards.toMutableList() --> error here


fun drawCard(): Card =

private fun getSuit(i: Int) = when(i / 13) {
        0 -> "Clubs"
        1 -> "Diamonds"
        2 -> "Hearts"
        else -> "Spades"
    }

}

1 Answer

Brooke Porter
Brooke Porter
7,425 Points

This is a bit late, but the line

var cardsInDeck = MutableList<Card> = cards.toMutableList()

should actually be

var cardsInDeck: MutableList<Card> = cards.toMutableList()

The first equals should be a colon. You are specifying that cardsInDeck is of type MutableList<Card>.