Java 中的 WITH 语句 [英] WITH statement in Java

查看:20
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆