This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why are there no objects for `true` and `false`?

4 replies
Antoras
Joined: 2010-05-23,
User offline. Last seen 1 year 19 weeks ago.

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

Stefan Langer
Joined: 2009-10-23,
User offline. Last seen 42 years 45 weeks ago.
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
>

Roland Kuhn 3
Joined: 2011-07-23,
User offline. Last seen 42 years 45 weeks ago.
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
>>

Antoras
Joined: 2010-05-23,
User offline. Last seen 1 year 19 weeks ago.
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.

Antoras
Joined: 2010-05-23,
User offline. Last seen 1 year 19 weeks ago.
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.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland