Java中的WITH语句 [英] WITH statement in Java
本文介绍了Java中的WITH语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VB.NET中,有一个WITH命令可以省略对象名称,只访问所需的方法和属性。例如:
In VB.NET there is the WITH command that lets you omit an object name and only access the methods and properties needed. For example:
With foo
.bar()
.reset(true)
myVar = .getName()
End With
Java中是否有这样的语法?
Is there any such syntax within Java?
谢谢!
推荐答案
没有。当表达式过长时,您可以做的最好的事情是将其分配给具有短名称的局部变量,并使用 {...}
来创建范围:
No. The best you can do, when the expression is overly long, is to assign it to a local variable with a short name, and use {...}
to create a scope:
{
TypeOfFoo it = foo; // foo could be any lengthy expression
it.bar();
it.reset(true);
myvar = it.getName();
}
这篇关于Java中的WITH语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文