我正在开发一个项目,我已经逆向设计了其他项目的代码。但是,代码包含了很多goto
语句和一个label
。
我尝试根据使用的标签重新排列代码,但没有获得正确的输出。我知道这可能超出你们的范围,因为你们不知道代码。
我的查询是关于如何在Android中使用带标签的语句,因为我无法找到任何特定的代码或演示示例。
以下是我正在使用的代码的代码段。
public static String computeIMEI()
{
String s1 = ((TelephonyManager)getInstance().getSystemService("phone")).getDeviceId();
if (s1 != null) goto _L2; else goto _L1
_L1:
String s = "not available";
_L4:
Log.d("IMEI", (new StringBuilder()).append("got deviceID='").append(s).append("'").toString());
return s;
_L2:
s = s1;
if (s1.equals("000000000000000"))
{
s = "1971b8df0a9dccfd";
}
if (true) goto _L4; else goto _L3
_L3:
}
非常感谢您的小帮助,谢谢。
答案 0 :(得分:1)
OMG!你在哪里得到它? :)
通常没有人使用goto
语句。这段代码很难阅读和理解。
if (s1 != null) goto _L2; else goto _L1
非常明显。如果s1等于null,我们转到_L1标签,然后转到_L4并从方法返回。
如果s1不等于null,我们转到_L2标签,再转到_L4(if (true) goto _L4; else goto _L3
,否则将执行分支)并从方法返回。
您的代码在"翻译"形式:
public static String computeIMEI() {
String s1 = ((TelephonyManager)getInstance().getSystemService("phone")).getDeviceId();
if (s1 != null) {
s = s1;
if (s1.equals("000000000000000")) {
s = "1971b8df0a9dccfd";
}
} else {
String s = "not available";
}
Log.d("IMEI", (new StringBuilder()).append("got deviceID='").append(s).append("'").toString());
return s;
}