如何将匿名类重新集成到ECD反编译器生成的Java代码中? [英] How to reintegrate anonymous classes into Java code produced by the ECD decompiler?

查看:124
本文介绍了如何将匿名类重新集成到ECD反编译器生成的Java代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个学校用的罐子,应该对它进行反编译,修改和重新评估。我使用Eclipse的ECD插件反编译了所有类文件,但是我认为我已经提取了一些匿名类,需要将它们重新合并到另一个类中。我有一个P类,然后还有五个名为P $ 1,P $ 2,...,P $ 5的类。

I have a jar for school that is supposed to be decompiled, modifed, and reevaluated. I decompiled all of the class files using the ECD plugin for Eclipse, but I think I have a few anonymous classes that were extracted and need to be merged back into another class. I have a class P, and then five more classes named P$1, P$2, ..., P$5.

这是P的问题部分:

public class P {
private ArrayList<Family> group;
private int marker;
private Integer primaryElement;
Comparator<Family> c;

public P(ArrayList<Family> g, Integer i, Comparator<Family> c) {
    this.marker = -1;
    this.group = new ArrayList(g);
    this.primaryElement = i;
    this.c = c;
}

/* Some unrelated methods */

public String printHeader() {
  return this.print(new 1(this));
}

public String printRow(Integer i) {
  return this.print(new 2(this, i));
}

public String printPad() {
  return this.print(new 3(this));
}

public Object printCost() {
  return this.print(new 4(this));
}

public String printLine() {
  return this.print(new 5(this));
}

这里是P $ 1。其他的非常相似。

Here is P$1. The others are very similar.

final class P$1 implements PrintCommand {
  P$1(P arg0) {
    this.this$0 = arg0;
  }

  public String print(Family f) {
    return String.format("%3d", new Object[]{Integer.valueOf(f.getId())});
  }
}

如果您想知道,PrintCommand是超级简单接口:

In case you're wondering, PrintCommand is a super simple interface:

public interface PrintCommand {
  String print(Family arg0);
}

如何将P $ 1合并回P中?另外, this.this $ 0 在P $ 1中意味着什么?

How can I get P$1 merged back into P? Also, what does this.this$0 mean in P$1?

推荐答案

在匿名类中,您可以使用 P.this 从封闭类中引用 this 。为此,java编译器将创建一个构造函数,该构造函数将一个名为 this $ 0 的字段设置为传递给该构造函数的引用。

In an anonymous class you can reference the this from the enclosing class with P.this. To do that, the java compiler will create a constructor, which will set a field named this$0 to the reference passed to the constructor.

原始代码可能看起来像这样:

The original code probably looked like this:

public String printHeader() { 
    return this.print(new PrintCommand() {
        public String print(Family f) {
            return String.format(%3d", f.getId());
        }
    );
}

编译器还有其他功能确实可以这样做,例如为封闭类的私有方法/字段添加访问方法,这些访问方法是在内部类中访问的,或者将内部类中使用的(有效)最终变量的值传递给构造函数。

There are other things the compiler does, for example adding accessor methods for private methods/fields from the enclosing class that are accessed in the inner class. Or passing the value of (effectively) final variables used in the inner class to the constructor.

从Java运行时的角度来看,没有匿名内部类,只有命名类。

From the perspective of the Java Runtime, there is no anonymous inner class, only named classes.

这篇关于如何将匿名类重新集成到ECD反编译器生成的Java代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆