谁能解释Android ViewBinding&#x27的bind()函数优化的Java代码?
我正在查看 app/build/ generated/data_binding_base_class_source_code 中自动生成的 ViewBinding 代码,并看到了 bind() 函数代码,但我无法理解它。
@NonNull
public static LayoutBindingBinding bind(@NonNull View rootView) {
// The body of this method is generated in a way you would not otherwise write.
// This is done to optimize the compiled bytecode for size and performance.
int id;
missingId: {
id = R.id.text_name;
TextView textName = ViewBindings.findChildViewById(rootView, id);
if (textName == null) {
break missingId;
}
return new LayoutBindingBinding((LinearLayout) rootView, textName);
}
String missingId = rootView.getResources().getResourceName(id);
throw new NullPointerException("Missing required view with ID: ".concat(missingId));
}
这个 MissingId: {} 块是什么,看起来像 goto + switch。评论已经说没有人会这样写,但这仍然是 Java 语言的特性。
谁能解释一下这是如何工作的,并且这个功能有名字吗?
我在 Java 方面有一些经验,但主要是在 Kotlin 上工作,所以在任何地方都找不到它。
I was looking at the auto-generated ViewBinding code in app/build/generated/data_binding_base_class_source_code and saw the bind() functions code and i cannot understand it.
@NonNull
public static LayoutBindingBinding bind(@NonNull View rootView) {
// The body of this method is generated in a way you would not otherwise write.
// This is done to optimize the compiled bytecode for size and performance.
int id;
missingId: {
id = R.id.text_name;
TextView textName = ViewBindings.findChildViewById(rootView, id);
if (textName == null) {
break missingId;
}
return new LayoutBindingBinding((LinearLayout) rootView, textName);
}
String missingId = rootView.getResources().getResourceName(id);
throw new NullPointerException("Missing required view with ID: ".concat(missingId));
}
What is this missingId: {} block it looks like goto + switch. The comment already says nobody would write like this, but still it is a Java language feature.
Can anyone explain me how this works and also does this feature has a name?
I have some experience in Java but mostly working on Kotlin, so cannot find it anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sissove_id
是break
使用的标签。您可以找到更多详细信息在这里。missing_id
is a label which is used by thebreak
. You can find more details here.