【发布时间】:2010-01-14 00:41:44
【问题描述】:
我有以下 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 如果可以的话,我会尝试删除这个问题。
【问题讨论】:
-
顺便说一句...我不是在争论反编译代码的正确性。我很惊讶
if(condition2) continue;与if(!condition2);相同这是否意味着执行会自动从正确的点继续(在这种情况下,是while循环的开头)? -
只是我还是他们在逻辑上不一样。在第一组代码中,如果
condition1 = true和someInteger = 1和condition2 = true则// other stuff here不会 被执行。但是在第二个代码块中具有相同条件// other stuff here会被执行。 -
@David - 我和你在一起,我没看到。
-
我的猜测是它在
// other stuff here部分中没有任何内容进行编译。这将使它在逻辑上是正确的 - 只有 OP 对它的解释是错误的(// other stuff here属于条件的“then”部分) -
@Anon: - 是的,我认为你是对的。
标签: java syntax decompiler