方法调用问题

时间:2016-09-04 19:00:35

标签: java

我在夜间编程时遇到了这个问题。

//Reader class isn't java.io but it's from third party library
public class ACR122U extends Reader {
      // This method is called from outside
      // This method overrides method of the Reader class
      @Override
      public void open(UsbDevice device) {
        new OpenTask().execute(device);
      }

  private class OpenTask extends AsyncTask<UsbDevice, Void, Exception> {
    @Override
    protected Exception doInBackground(UsbDevice... params) {
      Exception result = null;

      try {
        // There the problem (recursion) happens 
        // I don't want to call ACR122U.open() but Reader.open()
        // I cannot call super.open()  /super of OpenTask class is AsyncTask/
        open(params[0]);
      } catch (Exception e) {
        result = e;
      }

      return result;
    }
  }
}

我想知道是否可以在不更改open()方法名称的情况下解决问题。 有什么想法吗?

PS:新手在这里。

1 个答案:

答案 0 :(得分:0)

您要执行的操作的语法是:

ACR122U.super.open(params[0]);

但是,如果您正在谈论java.io.Reader,那么这不会起作用,因为Reader类没有定义open()方法;当然不是open(UsbDevice)方法。

相关问题