Andy Fingerhut <andy.finger...@gmail.com> writes:

> Boolean/FALSE is documented as being of type Boolean in Java
> documentation, yet it is treated by Clojure the same as primitive
> boolean false:
>
> user=> (clojure-version)
> "1.3.0"
> user=> (if Boolean/FALSE "logical true" "logical false")
> "logical false"
> user=> (identical? Boolean/FALSE false)
> true
>
> Does anyone know why?

That's the canonical false Boolean object you get when auto-boxing the
primitive boolean false, or when calling (Boolean/valueOf).

,----[ JLS: 5.1.7. Boxing Conversion ]
| At run time, boxing conversion proceeds as follows:
| 
|   - If p is a value of type boolean, then boxing conversion converts p
|     into a reference r of class and type Boolean, such that
|     r.booleanValue() == p
| 
|   [...]
| 
| If the value p being boxed is true, false, a byte, or a char in the
| range \u0000 to \u007f, or an int or short number between -128 and 127
| (inclusive), then let r1 and r2 be the results of any two boxing
| conversions of p. It is always the case that r1 == r2.
`----

Thus, checking "t != Boolean.FALSE" as clojure's `if` implementation
does is perfectly fine, because unless you've created a new Boolean
object yourself, the spec guarantees that you may check on identity.
(I totally agree with Rich that having a way to create new Boolean
instances is completely flawed.)

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to