询问如何在 Kotlin 中将 HashMap 转换为 ArrayListEN
最编程
2024-06-29 07:10:53
...
我收到一个类似这样的HashMap,我正在尝试将其转换为ArrayList
var snapshot = it.result!!.value as HashMap<String, Any>
val addresses: ArrayList<Address> = ArrayList<Address>(snapshot.values)
错误:
None of the following functions can be called with the arguments supplied.
<init>((MutableCollection<out TypeVariable(E)!>..Collection<TypeVariable(E)!>?)) where E = TypeVariable(E) for fun <E> <init>(c: (MutableCollection<out E!>..Collection<E!>?)): kotlin.collections.ArrayList<E> /* = java.util.ArrayList<E> */ defined in kotlin.collections.ArrayList
<init>(Int) where E = TypeVariable(E) for fun <E> <init>(initialCapacity: Int): kotlin.collections.ArrayList<E> /* = java.util.ArrayList<E> */ defined in kotlin.collections.ArrayList
我需要将这个列表分配给recyclerview适配器。
addressesAdapter = AddressAdapter(arrlstAddresses)
AddressAdapter类:
class AddressAdapter(private val addressList: ArrayList<Address>) : RecyclerView.Adapter<AddressAdapter.ViewHolder>() {
...
}
Address类:
class Address(
var addressLine1: String = "",
var addressLine2: String = "",
var city: String = "",
var state: String = "",
var pinCode: String = "",
) {}