Java - 跨类共享静态方法

时间:2016-11-10 06:46:47

标签: java oop

我有三个用于模拟mips32管道寄存器的类。它们看起来都很像。

class IDEX {
  public static Map<String, Integer> write;
  public static Map<String, Integer> read;

  static {
    Map<String, Integer> tempMap = new HashMap<String, Integer>();
    tempMap.put("incrPC", 0);
    tempMap.put("readReg1Value", 0);
    tempMap.put("readReg2Value", 0);
    tempMap.put("seOffset", 0);
    tempMap.put("writeReg_20_16", 0);
    tempMap.put("writeReg_15_11", 0);
    tempMap.put("function", 0);
    read = new HashMap<String, Integer>(tempMap);
    write = new HashMap<String, Integer>(tempMap);
  }
}

我还有一些实用工具方法可以从哈希映射中复制数据并格式化/打印它们。

如何在所有注册类中共享这些方法?通常,是否可以在处理各自静态变量的类之间共享方法?

0 个答案:

没有答案