我有以下簡單的Kotlin擴展功能:
// Get the views of ViewGroup
inline val ViewGroup.views: List
get() = (0..childCount - 1).map { getChildAt(it) }
// Get the views of ViewGroup of given type
inline fun ViewGroup.getViewsOfType() : List {
return this.views.filterIsInstance()
}
此代碼編譯并正常工作.但是,我希望函數getViewsOfType是一個屬性,就像視圖一樣. Android Studio甚至建議它.我讓AS進行重構,它會生成以下代碼:
inline val ViewGroup.viewsOfType: List
get() = this.views.filterIsInstance()
但是這段代碼沒有編譯.它會導致錯誤:“屬性的類型參數必須在其接收器類型中使用”
這是什么問題?搜索有關此錯誤的幫助似乎不會導致答案.