Android DataBinding:Kotlin中的@BindingAdapter不识别lambda表达式

这是我的BindingAdapter

 @BindingAdapter(value = *arrayOf("bind:commentsAdapter", "bind:itemClick", "bind:avatarClick", "bind:scrolledUp"), requireAll = false) fun initWithCommentsAdapter(recyclerView: RecyclerView, commentsAdapter: CommentsAdapter, itemClick: (item: EntityCommentItem) -> Unit, avatarClick: ((item: EntityCommentItem) -> Unit)?, scrolledUp: (() -> Unit)?) { //Some code here } 

initWithCommentsAdapter是一个顶级的函数

这是我的布局(一个重要部分):

 <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:bind="http://schemas.android.com/apk/res-auto"> <data> <variable name="viewModel" type="some.example.path.CommentsViewModel"/> <variable name="commentsAdapter" type="some.example.path.CommentsAdapter"/> </data> <android.support.v7.widget.RecyclerView ... bind:avatarClick="@{(item) -> viewModel.avatarClick(item)}" bind:itemClick="@{viewModel::commentClick}" bind:commentsAdapter="@{commentsAdapter}" bind:isVisible="@{viewModel.commentsVisibility}" bind:scrolledUp="@{() -> viewModel.scrolledUp()}" /> </layout> 

当我在布局中使用kotlin方法调用分配lambda时,在建立过程中出现这样的错误:

 e: java.lang.IllegalStateException: failed to analyze: java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:cannot find method avatarClick(java.lang.Object) in class some.example.path.CommentsViewModel ****\ data binding error **** 

或者如果我通过引用分配方法:

 e: java.lang.IllegalStateException: failed to analyze: java.lang.RuntimeException: Found data binding errors. ****/ data binding error ****msg:Listener class kotlin.jvm.functions.Function1 with method invoke did not match signature of any method viewModel::commentClick file:C:\Android\Projects\...\fragment_comments.xml loc:70:12 - 83:17 ****\ data binding error **** 

但是我有适当类型的方法,而不是Object

如何在布局中为Kotlin中的自定义@BindingAdapter分配Kotlin lambda?

编辑

viewModel的相关部分:

 class CommentsViewModel(model: CommentsModel): BaseObservable() { //Some binded variables here ... fun commentClick(item: EntityCommentItem) { //Some code here } fun avatarClick(item: EntityCommentItem) { //Some code here } fun scrolledUp() { //Some code here } ... } 

变量绑定工作得很好