2015-01-18 15:36:36 -08:00
|
|
|
^title Object Class
|
|
|
|
|
|
2015-05-01 07:55:28 -07:00
|
|
|
## Static Methods
|
|
|
|
|
|
2015-11-07 13:00:24 -08:00
|
|
|
### **same**(obj1, obj2)
|
2015-05-01 07:55:28 -07:00
|
|
|
|
|
|
|
|
Returns `true` if *obj1* and *obj2* are the same. For [value
|
2021-04-16 00:29:26 -04:00
|
|
|
types](../../values.html), this returns `true` if the objects have equivalent
|
2015-05-01 07:55:28 -07:00
|
|
|
state. In other words, numbers, strings, booleans, and ranges compare by value.
|
|
|
|
|
|
|
|
|
|
For all other objects, this returns `true` only if *obj1* and *obj2* refer to
|
|
|
|
|
the exact same object in memory.
|
|
|
|
|
|
|
|
|
|
This is similar to the built in `==` operator in Object except that this cannot
|
|
|
|
|
be overriden. It allows you to reliably access the built-in equality semantics
|
|
|
|
|
even on user-defined classes.
|
|
|
|
|
|
2015-03-27 07:43:36 -07:00
|
|
|
## Methods
|
|
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **!** operator
|
|
|
|
|
|
2015-11-07 13:00:24 -08:00
|
|
|
Returns `false`, since most objects are considered [true][].
|
|
|
|
|
|
|
|
|
|
[true]: control-flow.html#truth
|
2015-01-18 15:36:36 -08:00
|
|
|
|
|
|
|
|
### **==**(other) and **!=**(other) operators
|
|
|
|
|
|
2015-05-01 07:55:28 -07:00
|
|
|
Compares two objects using built-in equality. This compares [value
|
2021-04-16 00:29:26 -04:00
|
|
|
types](../../values.html) by value, and all other objects are compared by
|
2015-05-01 07:55:28 -07:00
|
|
|
identity—two objects are equal only if they are the exact same object.
|
2015-01-18 15:36:36 -08:00
|
|
|
|
2015-11-07 13:00:24 -08:00
|
|
|
### **is**(class) operator
|
|
|
|
|
|
|
|
|
|
Returns `true` if this object's class or one of its superclasses is `class`.
|
|
|
|
|
|
2020-06-05 14:57:20 -07:00
|
|
|
<pre class="snippet">
|
|
|
|
|
System.print(123 is Num) //> true
|
|
|
|
|
System.print("s" is Num) //> false
|
|
|
|
|
System.print(null is String) //> false
|
|
|
|
|
System.print([] is List) //> true
|
|
|
|
|
System.print([] is Sequence) //> true
|
|
|
|
|
</pre>
|
2015-11-07 13:00:24 -08:00
|
|
|
|
|
|
|
|
It is a runtime error if `class` is not a [Class][].
|
|
|
|
|
|
2015-01-18 15:36:36 -08:00
|
|
|
### **toString**
|
|
|
|
|
|
|
|
|
|
A default string representation of the object.
|
|
|
|
|
|
|
|
|
|
### **type**
|
|
|
|
|
|
2015-11-07 13:00:24 -08:00
|
|
|
The [Class][] of the object.
|
|
|
|
|
|
|
|
|
|
[class]: class.html
|