I have a MutableList<Card> called cards that I am sorting based on one of the properties, using the sortedWith function. This returns a sorted generic list type, so a cast is necessary. However, when I cast the list, it crashes with a ClassCastException:
private var cards: MutableList<Card> = ArrayList()
...
cards = cards.sortedWith(compareBy{it.face}) as ArrayList<Card>
java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
EDIT: I just realized I need to use the more generic type of cards for the cast, MutableList<Card>. Now, can someone explain why the cast with ArrayList fails?