- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why are there no objects for `true` and `false`?
I don't understand why there currently are no objects for both keywords
`true` and `false`. Because of Java interoperability I understand why
`null` could not be deleted, but I can't see a reason for the Boolean
values. If there are objects like `True` and `False`, they could be
transformed to the primitive ones by the compiler. And if one wants to
call a method on the Boolean objects the compiler could create a wrapper.
Is there a special reason why this break in the object system of Scala
is suffered or is this up to now unimplemented behavior?
Antoras










Re: Why are there no objects for `true` and `false`?
true and false are Boolean objects in scala
2011/7/23 Antoras :
> I don't understand why there currently are no objects for both keywords
> `true` and `false`. Because of Java interoperability I understand why `null`
> could not be deleted, but I can't see a reason for the Boolean values. If
> there are objects like `True` and `False`, they could be transformed to the
> primitive ones by the compiler. And if one wants to call a method on the
> Boolean objects the compiler could create a wrapper.
>
> Is there a special reason why this break in the object system of Scala is
> suffered or is this up to now unimplemented behavior?
>
> Antoras
>
Re: Why are there no objects for `true` and `false`?
Am Sa 23 Jul 2011 23:21:31 CEST, Stefan Langer schrieb:
> true and false are Boolean objects in scala
>
And why are they written in lower-case? They don't look as objects.
Re: Why are there no objects for `true` and `false`?
or, to put it slightly differently: false and true are treated basically the same way as 0 and 1. There are 8 non-object types on the JVM which receive special treatment, so the Java interop argument equally applies to all of them.
On Jul 23, 2011, at 23:21 , Stefan Langer wrote:
> true and false are Boolean objects in scala
>
> 2011/7/23 Antoras :
>> I don't understand why there currently are no objects for both keywords
>> `true` and `false`. Because of Java interoperability I understand why `null`
>> could not be deleted, but I can't see a reason for the Boolean values. If
>> there are objects like `True` and `False`, they could be transformed to the
>> primitive ones by the compiler. And if one wants to call a method on the
>> Boolean objects the compiler could create a wrapper.
>>
>> Is there a special reason why this break in the object system of Scala is
>> suffered or is this up to now unimplemented behavior?
>>
>> Antoras
>>
Re: Why are there no objects for `true` and `false`?
Am Sa 23 Jul 2011 23:42:52 CEST, Roland Kuhn schrieb:
> or, to put it slightly differently: false and true are treated basically the same way as 0 and 1. There are 8 non-object types on the JVM which receive special treatment, so the Java interop argument equally applies to all of them.
That is true, but I don't understand why `true` and `false` should also
be written as the same as in Java. In Scala they can be represented by
objects, not classes.