'Initialize a Java Collection in Class that was declared in Interface

Declared a Vector in the Interface and set it to null, want to initialize it later in the class that implemented the Interface, java is giving error with the following code, how can i initialize it any other way?

import java.util.Vector;

interface machine {
    Vector<Integer> temp = null;
    public int compute();
}

class App implements machine {
    App(Vector<Integer> x) {
        //error here, can't assign value to temp as it is declared in interface, any other way of initializing??
        temp = x;
    }

    @Override
    public int compute() {
        int sum = 0;
        for (int x : temp) {
            sum += x;
        }
        return sum;
    }
}

public class Finals {
    public static void main(String[] args) {
        Vector<Integer> x = new Vector<>();
        for (int i = 0; i < 10; i++) {
            x.add(i);
        }
        App a = new App(x);
        System.out.println(a.compute()); 
    }
}



Solution 1:[1]

As per my understanding you can't do it, because interface variables are static final hence you have to initialize in interface itself.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sathiya prakash