欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

询问如何在 Kotlin 中将 HashMap 转换为 ArrayListEN

最编程 2024-06-29 07:10:53
...

我收到一个类似这样的HashMap,我正在尝试将其转换为ArrayList

代码语言:javascript
复制
var snapshot = it.result!!.value as HashMap<String, Any>
val addresses: ArrayList<Address> = ArrayList<Address>(snapshot.values)

错误:

代码语言:javascript
复制
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适配器。

代码语言:javascript
复制
addressesAdapter = AddressAdapter(arrlstAddresses)

AddressAdapter类:

代码语言:javascript
复制
class AddressAdapter(private val addressList: ArrayList<Address>) : RecyclerView.Adapter<AddressAdapter.ViewHolder>() {
   ...
}

Address类:

代码语言:javascript
复制
class Address(
var addressLine1: String = "",
var addressLine2: String = "",
var city: String = "",
var state: String = "",
var pinCode: String = "",
) {}