You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$(P The $(D is) operator compares for identity of expression values.
657
657
To compare for nonidentity, use $(D e1 !is e2).
658
658
The type of the result is $(D bool). The operands
659
659
undergo the $(USUAL_ARITHMETIC_CONVERSIONS) to bring them to a common type before
660
660
comparison.
661
661
)
662
662
663
-
$(P For class objects, identity is defined as the object references
664
-
are for the same object. Null class objects can be compared with
665
-
$(D is).
663
+
$(P For class / interface objects, identity is defined as the object references being identical.
664
+
Null class objects can be compared with `is`.
665
+
Note that inferface objects need not have the same reference of the class they were cast from.
666
+
To test whether an `interface` shares a class instance with another `interface` / `class` value, cast both operands to `Object` before comparing with `is`.
667
+
)
668
+
669
+
$(SPEC_RUNNABLE_EXAMPLE_RUN
670
+
---
671
+
interface I { void g(); }
672
+
interface I1 : I { void g1(); }
673
+
interface I2 : I { void g2(); }
674
+
interface J : I1, I2 { void h(); }
675
+
676
+
class C : J
677
+
{
678
+
override void g() { }
679
+
override void g1() { }
680
+
override void g2() { }
681
+
override void h() { }
682
+
}
683
+
684
+
void main() @safe
685
+
{
686
+
C c = new C;
687
+
I i1 = cast(I1) c;
688
+
I i2 = cast(I2) c;
689
+
assert(i1 !is i2); // not identical
690
+
assert(c !is i2); // not identical
691
+
assert(cast(Object) i1 is cast(Object) i2); // identical
692
+
}
693
+
---
666
694
)
667
695
668
696
$(P For struct objects and floating point values, identity is defined as the
0 commit comments