0

所有,我试图阅读一些从 jd-gui 生成的代码。它看起来像下面。

    public class agrPullingAgentStudy
    {
      private static final String PGPR_ID = "agrPullingAgentStudy";
      private static Timer m_tmStudy = null;
      private static Timer m_tmNonStop = null;
      private static Timer m_tmRemove = null;
      private static String m_szManual = "";
      private static String m_szProcRule = "";
      private static String m_szExecHosp = "";
      private static HashMap<String, HashMap> m_hRemoteAll = new HashMap();
      private static HashMap<String, String> m_hProcRule = null;
      private static int m_nImageAfterMins = -120;
      private static boolean m_bDoProcess = false;
      private static Date m_dAliveDT = new Date();
      private static final String LINE_SEP = System.getProperty("line.separator");
    ....



      private class dcmStudySchedule
        extends TimerTask
      {

        public void run()
        {
          String FUN_ID = "runStudySchedule";
          StringBuffer szBuffer = new StringBuffer();
          agrPullingAgentStudy.access$002(new Date());

          ...
        }


       ....
       agrPullingAgentStudy.access$402(agrPullingAgentStudy.m_szExecHosp.substring(0, agrPullingAgentStudy.m_szExecHosp.length() - 1));
       ...
      }
    }

该类agrPullingAgentStudy包括一个名为 dcmStudySchedule 的内部类。并在内部类中。

我无法理解的是access$xxx我已经知道这是因为如果内部类试图访问外部类成员,那么生成的代码将用户access$xxx代表这种代码。我只想知道是否有任何解决方法可以解决此问题。或者我怎样才能理解这段代码?谢谢。

4

1 回答 1

1

以下代码段将生成您的反编译源。

import java.util.Date;
import java.util.TimerTask;

public class agrPullingAgentStudy {

    private static Date m_dAliveDT = new Date();

    private class dcmStudySchedule extends TimerTask {

        public void run() {
            m_dAliveDT = new Date();
        }
    }
}

要了解agrPullingAgentStudy.access$002(new Date())它,对字节码级别进行一些调查会很有帮助。

先编译源码javac agrPullingAgentStudy .java。它生成两个*.class文件。agrPullingAgentStudy.classagrPullingAgentStudy$dcmStudySchedule.class。(好的,直到现在没有惊喜)。

m_dAliveDT要从类中访问变量,dcmStudySchedule编译器会在agrPullingAgentStudy. 签名是static Date access$002(Date var0)

这个结论是怎么得出的?...简单:使用javap.

javap -c -v agrPullingAgentStudy.class

显示生成的字节码

static java.util.Date access$002(java.util.Date);
  descriptor: (Ljava/util/Date;)Ljava/util/Date;
  flags: ACC_STATIC, ACC_SYNTHETIC
  Code:
    stack=2, locals=1, args_size=1
       0: aload_0
       1: dup
       2: putstatic     #1        // Field m_dAliveDT:Ljava/util/Date;
       5: areturn

引用常量池中的索引(上面的命令#1也会显示)javap

Constant pool:
   #1 = Fieldref       #5.#21   // agrPullingAgentStudy.m_dAliveDT:Ljava/util/Date;
...

作为 Java 源代码,它看起来像

static Date access$002(Date d) {
    m_dAliveDT = d;               // putstatic #1
    return d;                     // areturn
}
于 2016-04-28T10:13:58.907 回答