0

I am trying to create an array of a specific Data Type, however I am getting a Type Safety error I cannot understand/solve.

The data type

private static class Component<F> {

    private int index;
    private F value;

    public Component(int index, F value) {
        this.index = index;
        this.value = value;
    }

And the code where I try to initialize the array

private Component<F>[] table;

// Constructor
public SparseVector(int n, F f) {
    table = new Component[n];       
}

However I get the said type safety error, and upon running the program inspecting the variables in debugging I get the message "Type has not been loaded occurred while retrieving component type of array."

3
  • What debugger gives you that message? Commented May 23, 2015 at 18:23
  • Warning is little different than error. Anyway general rule is that arrays are generics don't mix well so you should avoid combining them. Instead of Component<F>[] array use collection like List<Component<F>>. Commented May 23, 2015 at 18:26
  • @Pshemo I have seen that suggestion in other similar questions to mine, however it was requested that I use an array. Commented May 23, 2015 at 18:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.