2
我有这段代码。它将与代表findViewById
。我可以推断代表中属性的类型吗?
val backgroundImage: ImageView by lazy { view<ImageView>(R.id.item_component_section_background) }
fun <T: View> view(id : Int) : T {
val view : View = findViewById(id) ?: throw IllegalArgumentException("Given ID could not be found in current layout!")
@Suppress("UNCHECKED_CAST")
return view as T
}
有什么办法去除view<ImageView>
在慵懒块类似view
?我能得到或推断函数view()
中的属性类型吗?
这不是我想的,但它是我想要的结果!像那样,我不需要两次写这个类型。 –