Re: Empty constants



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.
.



Relevant Pages

  • Re: Logging oddity: handlers mandatory in every single logger?
    ... for example when a Formatter ... string-> int is an internal hack to map easilty map Level name to their int identifier. ... Ah, interesting, I didn't think it could be defined as empty. ... Note how progammatically the list of handlers is set to an empty list. ...
    (comp.lang.python)
  • Re: Learning Scheme - critique
    ... product should be the product of the sizes of the sets - but the empty ... If you make the empty cartesian product be ), ... simply trust `map' to do the right thing with the empty list. ... product of other-sets or more in two branches, ...
    (comp.lang.scheme)
  • RE: Dynamic Maps In Orchestrations
    ... need to do a lot of checking for empty results and so on... ... If you give a wrong map type or the message ... > We did the whole untyped document dynamic mapping approach in our project. ... >> "construct keywords. ...
    (microsoft.public.biztalk.general)
  • Re: Question about |P(X)| > |X|
    ... > In all the proofs that the cardinality of the power set of a set is ... The proof shows that such a mapping can't be a bijection. ... a map, then show that no matter what map you choose, ... empty set and others where it isn't. ...
    (sci.math)
  • Re: Empty constants
    ... final, read-only, empty constants for common classes. ... 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. ...
    (comp.lang.java.programmer)