【发布时间】:2015-11-15 22:04:55
【问题描述】:
我刚刚反编译了一些java代码,发现了类似的东西
public class Example {
private static String test(String s) {
String[] test = new String[1];
ExampleObject exampleObject = new ExampleObject() {
public void testMethod1() {
Example.this[0] = "1";//what's that?
}
public void testMethod2() {
Example.this[0] = "2";//what's that?
}
};
//some code with exampleObject and s
return test[0];
}
}
我不想发布原始的反编译代码,因为我不知道我是否被允许。但这原则上是相同的代码。原始反编译代码中没有超类,也没有字段。
我知道我可以通过Example.this 访问Example 当前实例的字段和方法。但我从未见过像Example.this[0] 这样的代码。另外String[] test 不是Example 的字段,它是private static String test(String s) 方法中的一个变量。我尝试用 eclipse 编译该代码,但出现错误。
编辑:问题是该代码的作用是什么?还是反编译器的bug?
【问题讨论】:
-
你确定是
Example.this[0]而不是Example.this.something[0]? -
是的,我确定,这就是我想知道的原因
-
而且我很确定
Example.this[0]应该修改String[] test,否则代码将没有意义。 -
投反对票的原因是什么?我可以/应该改进什么(针对我的下一个问题)?
标签: java arrays this decompiling decompiler