I have a generic class that looks similar to this
public class NetworkItems<T> { private Status status; private T items; public NetworkItems() { this.status = Status.FAILURE; this.items = null; } public NetworkItems(Status status, T listItems) { this.status = status; this.items = listItems; } public NetworkItems(Status status) { this.status = status; this.items = null; } public Status getStatus() { return status; } public void setStatus(Status status) { this.status = status; } public T getItems() { return items; } public void setItems(T items) { this.items = items; } } All I want to do is check if the parameter T is a List of any kind in the constructors. If T is a List<> then I want to instantiate it into a new List<>();
I tried the following code
if (this.items instanceof List) { this.items = Collections.emptyList(); } or this
this.items = new ArrayList<>(); But I keep getting an error because I couldn't give a parameter type. How do I make sure that I instantiate the items with a new List if the generic type T is a List?
NetworkItems<List>?