在a
循环中定义if
变量,需要传递else if
循环中更新的值。示例:
if(document.getVersionIdentifier().getValue().equals("00"))
{
String a=attrs.put(CREATED_BY, shortenFullName(document
.getCreatorFullName()));
// Value a = USer1
}
else if(document.getVersionIdentifier().getValue().equals("01"))
{
String b = attrs.put(document,a);
// Need value of b to be User1
}
答案 0 :(得分:2)
首先,你的问题毫无意义。如果执行了if
语句,则else if
将被忽略,因此将if
正文中的任何数据传递给else if
正文都无关紧要。
但是,您可以做的是将else if
更改为单独的if
语句,并在a
机构之外定义if
。原则上这可能看起来像这样 - 需要根据你真正想要的东西进行调整(从你的问题中不清楚)。
String a = null;
if(document.getVersionIdentifier().getValue().equals("00"))
{
a = attrs.put(CREATED_BY, shortenFullName(document.getCreatorFullName()));
// Value a = User1
}
// The value of a can be either null or set during the if statement above.
// If a has a value the next if statement will always be false so the value of a
// will be always null if the next if statement is true.
if(document.getVersionIdentifier().getValue().equals("01"))
{
String b = attrs.put(document,a);
// Need value of b to be User1
}