为什么不更改计数器值

时间:2019-05-03 21:47:35

标签: java list

in的计数器在变化,但是在LInkedList中,每个t都具有i的最大值。我在做什么错了?

public class Test {


    public static void main(String[] args) {
        getUnit("LPE", new LowPowerEngine()).getCounter();
    }

    public static <T extends IUnitSpecification> T getUnit(String key, T t) {
        return t = controlUnitAvailability(key, t);
    }

    private static <T extends IUnitSpecification> T controlUnitAvailability(String key, T t) {
        LinkedList<T> unitStock = new LinkedList<>();

        int minimumAmount = 3;
        int partySize = 15;
        int counter = 0;

        if (unitStock.size() < minimumAmount) {

            for (int i = 0; i < partySize; i++) {
                counter++;
                t.setCounter(counter);
                unitStock.addLast(t);
            }
            for (T t1 : unitStock) {
                System.out.println(t1.getCounter());
            }
        }
        return t;
    }
}

0 个答案:

没有答案