我有以下java代码片段
while (condition1){
switch (someinteger){
case 1:
if(condition2) continue;
// other stuff here
break;
// other cases here
}
}
一切都很好。当我生成一个类文件,然后使用免费工具(JD-gui)反编译它时,我得到以下代码。
while (condition1){
switch (someinteger){
case 1:
if(!condition2);
// other stuff here
break;
// other cases here
}
}
因此它将 if(condition2) continue;
更改为 if(!condition2);
我找不到有关其他 if 语句(不带大括号)的任何信息。
谁能解释一下这里的逻辑吗?提前致谢。
编辑:我做了一些更多的测试,反编译器无法正常工作。
这是之前的代码:
public void strip(InputStreamReader f1, OutputStreamWriter f2) throws IOException{
int commentON=0, quoteON=0;
int b1;
while ((b1 = f1.read()) != -1){
switch ((char) b1){
case '\\':
if (commentON==0){
quoteON = 1;
break;
}
continue;
case '\n':
if (commentON>0){ commentON=0; continue; }
break;
case '%':
if (commentON>0) continue;
if (quoteON>0) { quoteON=0; break; }
commentON=2;
continue;
default:
if (commentON>0) continue;
if (quoteON>0) quoteON=0;
break;
}
f2.write(b1);
}
}
这是反编译的代码
public void strip(InputStreamReader f1, OutputStreamWriter f2) throws IOException
{
int commentON = 0; int quoteON = 0;
while ((b1 = f1.read()) != -1)
{
int b1;
switch ((char)b1)
{
case '\\':
if (commentON == 0);
quoteON = 1;
break;
case '\n':
if (commentON <= 0) break label109; commentON = 0; break;
case '%':
if (commentON <= 0);
if (quoteON > 0) { quoteON = 0; break label109: }
commentON = 2;
break;
}
if (commentON <= 0);
if (quoteON > 0) quoteON = 0;
label109: f2.write(b1);
}
}
抱歉打扰大家了。 :P 如果可以的话,我会尝试删除这个问题。
最佳答案
反编译器几乎不可能重建您的原始语法,因为它们正在处理编译器对代码的解释。
你编写java代码,java编译器将其编译为字节码。
然后,反编译器尝试从字节码创建 Java 代码。
由于两个代码片段在逻辑上是相同的,因此反编译器已经完成了它的工作。
编辑(看到您的评论):
实际上,反编译器很可能(而且这种情况很常见)犯了错误。
语句if(!condition2);
本质上没有任何效果(假设condition2确实是一个 boolean 值而不是伪代码)。
因此,无论反编译版本中的condition2
如何,您的第一个//other stuff here
都会被处理。
你确定反编译后的代码可以正常工作吗?
关于JAVA:如果没有大括号,关系继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2061440/