代码之家  ›  专栏  ›  技术社区  ›  chris01

Java:泛型和继承

  •  -2
  • chris01  · 技术社区  · 7 年前

    我正在构建一个类引导程序,用于引导实现可引导的其他类。

    // interface that every class must implement that needs to be bootstrapped
    class Bootstrappable implements Runnable {
      public foo();
    }
    
    class MyApp implements Bootstrappable {
      public void foo() {}
    }
    
    class Bootstrap {
      private Bootstrappable instance;
    
      public bootstrap(Class<Bootstrappable> b) {
        instance = b.newInstance();
        ...
      }
    }
    

    new Bootstrap().bootstrap(MyApp.class);
    

    类型bootstrap中的方法bootstrap(类Bootstrappable)不适用于参数(类MyApp)

    1 回复  |  直到 7 年前
        1
  •  1
  •   marstran    7 年前

    如果你需要一个类来实现 Bootstrappable

    Class<? extends Bootstrappable>