我有一些Java代码以两种方式使用大括号
I have some Java code that uses curly braces in two ways
// Curly braces attached to an 'if' statement: if(node.getId() != null) { node.getId().apply(this); } // Curly braces by themselves: { List<PExp> copy = new ArrayList<PExp>(node.getArgs()); for(PExp e : copy) { e.apply(this); } } outAMethodExp(node);第一个之后的那些独立花括号是什么语句是什么意思?
What do those stand-alone curly braces after the first if statement mean?
推荐答案额外括号的唯一目的是提供范围限制。 列表< PExp> copy 只会存在于这些大括号内,并且不会在它们之外。
The only purpose of the extra braces is to provide scope-limit. The List<PExp> copy will only exist within those braces, and will have no scope outside of them.
如果这是生成的代码,我假设代码 - 生成器执行此操作以便它可以插入一些代码(例如此代码),而不必担心它插入了多少次列表< PExp>复制,如果此片段多次插入同一方法,则无需担心可能重命名变量。
If this is generated code, I assume the code-generator does this so it can insert some code (such as this) without having to worry about how many times it has inserted a List<PExp> copy and without having to worry about possibly renaming the variables if this snippet is inserted into the same method more than once.
更多推荐
Java中的花括号是什么意思?
发布评论