Home  >  Q&A  >  body text

java - <T>泛型为什么在Object[]的前面?为什么都是用t代替,下面的代码却报错?

大家讲道理大家讲道理2716 days ago536

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:58:34

    Static methods cannot reference generics defined on the class, static generic methods should be used. You can use it in Object[]之前加<T>表示这是一个静态泛型方法。使用静态泛型方法要在List<T>前面加<T> as follows

        public static <T>  List<T> name() {
            List<T> list = new ArrayList<T>();
            return list;
        }

    reply
    0
  • PHPz

    PHPz2017-04-18 10:58:34

    ...Generics are for definition, you need to specify the type when using them

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:58:34

    There is an introduction in think in java

    reply
    0
  • Cancelreply