Shared array in java release

I have this bit of code, and it continues to say that it cannot create a shared array, but I don't have one in the Node class, just in the Object field. The Node class is an inner class. Why is he doing this?

public class TernarySearchTrie<E> implements TrieInterface<E> {

    private Node[] root = new Node[256];
    private int size = 0;

    private class Node {
        char c;
        Node left, mid, right;
        Object value;
    }
}
+4
source share
2 answers

Add the modifier staticto the Node class:

private static class Node {
    char c;
    Node left, mid, right;
    Object value;
}

Without static, it depends on the TernarySearchTrie class, which has generics.

+4
source

What are you new Node[256]really doing in the problem TernarySeachTrie<E>.Node[256]. One solution is to use the raw type:

Node[] root = TernarySearchTrie.Node[256];

Of course, the compiler gives you a warning for this.

+2

All Articles