在我的应用程序中使用数据绑定时,编译时会收到以下警告:
Warning:Method references using '.' is deprecated. Instead of 'handler.onItemClick', use 'handler::onItemClick'
请参阅下面的XML.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable name="handler" type="ClickHandler"/>
<variable name="active" type="boolean"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="@{!active ? handler.onItemClick : null}"
android:background="@color/backgroundWhite"/>
</RelativeLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
请注意:来自条件声明
非常直截了当的消息,直到我改变'.' 至 '::'.
android:onClick="@{!active ? handler::onItemClick : null}"
Run Code Online (Sandbox Code Playgroud)
由于onItemClick在条件语句中,它似乎将两个::'中的第一个解释为条件的'else'语句.在第二个':',我收到错误:
<expr> expected, got ':'
编辑:正如@CommonsWare在评论中建议的那样,反转语句
"@{active ? null : handler::onItemClick}"
也没有帮助,显示了类似的错误(见注释)
编辑2:显然,当剥离条件语句,留下时"@{handler::onItemClick}",它仍然会出错:'!=', '%', '*', '+', ',', '-', '.', '/', <, <<, <=, '==', '>', '>=', '>>', …