jameshfisher
jameshfisher

Reputation: 36405

Functional Java: how do I construct an empty list?

I wish to construct the empty list of type List<String>. The best I can come up with that satisfies the type-checker is:

(List<String>) (Object) List.nil()

which is terribly ugly. Is there something better?

Upvotes: 0

Views: 115

Answers (2)

Shlomi
Shlomi

Reputation: 4748

Here is another option:

List<String> l = List.<String>nil();

Upvotes: 3

JonasVautherin
JonasVautherin

Reputation: 8033

This should do it:

List<String> myList = list();

Upvotes: 2

Related Questions