In vala, ==
compares the content for string type. I want to compare two objects (including strings) reference like java's obj == obj2
. I couldn't find a document about it.
How to do it?
In vala, ==
compares the content for string type. I want to compare two objects (including strings) reference like java's obj == obj2
. I couldn't find a document about it.
How to do it?
You can access the underlying byte array to compare it by reference.
string a = "a";
unowned string b = a;
assert (a.data == b.data);
More generally, comparing references is not relevant because string can only have a single owner. If you have two strong references on string
objects, they are guarantee to be different.
This is why b
has been assigned with a weak reference from a
, otherwise a copy would be made.