Re: Empty constants
- From: Spud <fake@xxxxxxxxxxx>
- Date: Mon, 29 Dec 2008 17:14:50 -0600
Eric Sosman wrote:
Spud wrote:I've just created a static class that contains a number of static, final, read-only, empty constants for common classes. For example, I've got:
public static final Map MAP = new EmptyMap();
where EmptyMap is a map implementation that has zero elements and throws an UnsupportedOperationException if you try to modify it.
[...]
Question: surely somebody, somewhere must be doing this already. Is there a standard class out there that everybody uses for this purpose? Maybe something in Apache Commons?
... or maybe something in java.util.Collections?
Like java.util.Collections.EMPTY_MAP, perhaps? See
also java.utilCollections.emptyMap(), which is a method
rather than a constant, but which plays nicely with
generics.
Perfect. That eliminates all Collections constants. Now I just have EMPTY_ITERATOR, empty Object arrays, and a few things like empty StringBuffers.
.
- Follow-Ups:
- Re: Empty constants
- From: Lew
- Re: Empty constants
- From: Mark Rafn
- Re: Empty constants
- References:
- Empty constants
- From: Spud
- Re: Empty constants
- From: Eric Sosman
- Empty constants
- Prev by Date: Re: Empty constants
- Next by Date: Re: Empty constants
- Previous by thread: Re: Empty constants
- Next by thread: Re: Empty constants
- Index(es):
Relevant Pages
|