How to initialize List<E> in empty class constructor?

Posted by Nazgulled on Stack Overflow See other posts from Stack Overflow or by Nazgulled
Published on 2010-05-21T14:25:14Z Indexed on 2010/05/21 14:30 UTC
Read the original article Hit count: 224

Hi,

The following code obviously doesn't work because List<E> is abstract:

public class MyList {
    private List<E> list;

    public MyList() {
        this.list = new List<E>();
    }
}

How can I initialize MyList class with an empty constructor if I need the list variable to be a LinkedList or a ArrayList depending on my needs?

© Stack Overflow or respective owner

Related posts about java

Related posts about abstract-class