简体   繁体   English

创建通用列表

[英]create a Generic List

public class Sortieralgorithmen<T extends Comparable <T>>
{
    public static void main (String[] args) throws IOException
    {
         UserInput read = new UserInput();
         ArrayList<Integer> list = read.type(muster, type, length, rounds);
         ArrayList<T> list = read.type(muster, type, length, rounds);
    }
 }

Why is the first working and the second is not?为什么第一个有效而第二个无效?

type is a method in the class UserInput . typeUserInput type中的一个方法。 There I will fill the Array.在那里我将填充数组。

Your class has a type parameter T , but your main is a static method.你的类有一个类型参数T ,但你的main是一个静态方法。

Just like non-static fields the type parameter T is only accessible in non-static methods (as there is no instance to "take" the type T from in static methods).就像非静态字段一样,类型参数T只能在非静态方法中访问(因为在静态方法中没有实例可以“获取”类型T )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM