-1

I just decompiled some java code and found something like that

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];
    }
}

I don't want to post the original decompiled code, because I don't know if I am allowed to. But this is in principle the same code. There are no super classes and no fields in the original decompiled code.

I know that I can do Example.this to access the fields and methods of the current instance of Example. But I have never seen a code like Example.this[0]. Also String[] test is not a field of Example, it's a variable in the private static String test(String s) method. I tried to compile that code with eclipse, but I get errors.

Edit: The question is what does that code do? Or is it a bug of the decompiler?

stonar96
  • 1,359
  • 2
  • 11
  • 39

1 Answers1

2

It's a bug in the decompiler. Use a better decompiler. Have you tried Procyon or Krakatau?

vlp
  • 7,811
  • 2
  • 23
  • 51
Antimony
  • 37,781
  • 10
  • 100
  • 107
  • No, I downloaded the decompiler anywhere a long time ago. I don't even know the name of the decompiler. It's called "Java Decompiler" but I had never problems with that decampiler. I will try it with one of the decompiler you proposed and report the result. Thank you! – stonar96 Nov 15 '15 at 22:46
  • I tried it with another decompiler and now `Example.this[0]` is replaced with `val$test[0]`. So it was a bug of the decompiler – stonar96 Nov 15 '15 at 23:10