问题描述
以下代码通过首先向下转换来访问变量,我想知道该方法的返回类型是否返回与我正在使用的变量相同的别名(ContainerPieceVolumesBinding binding
) ,或作为方法参数传入的参数。
我已经测试了代码,并且看起来运行良好,问题在于可能存在对同一变量的第二个访问点(该第二个访问点是可选的)。
从理论上讲,这第二个访问点将使用viewBind别名,而不是我在此处使用的转换版本。
如果我不返回方法参数抛出的相同别名,而是返回向下转换的版本,会更安全吗?
@SuppressWarnings("unchecked")
@Override
public ViewDataBinding setData(ViewDataBinding viewBind,@NonNull String bindingTag) {
BindingVisitorsBaseAdapter adapter = new BindingVisitorsBaseAdapter(
TAG
);
adapter.setCompletePendingBindings(
pendingBindings
);
//This is the downcasted alias
ContainerPieceVolumesBinding binding = (ContainerPieceVolumesBinding) viewBind;
binding.pieceVolumesContainer.setAdapter(adapter);
observer = new ObjectNotifier(
) {
@Override
public Notifier onNotified() {
return (response,responseType) -> {
switch (responseType) {
case SUBMIT_LIST :
List<BindingVisitor> pieceVolumes = (List<BindingVisitor>) response[0];
((BindingVisitorsBaseAdapter)binding.pieceVolumesContainer.getAdapter()).submitList(pieceVolumes);
break;
case QUANTITY_CHANGE:
onQuantityChanged.onChanged(getValues(binding.pieceVolumesContainer));
break;
}
};
}
};
observer.notifyResponse(SUBMIT_LIST,new ArrayList<>());
// returning the original version here
return viewBind;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)