1

The eclipse dart plugin shows in 'variables' view something like that: enter image description here

What is the meaning of 'id' visible in the 'value' column? Is 'id' unique? How can I determine wether two instances are the same during debugging? Do I need to override toString() in all classes?

kolar
  • 1,010
  • 1
  • 9
  • 21

2 Answers2

1

Sure, you can override toString in your classes.

class MyClass {
  String someValue = 15;

  @override // not necessary
  String toString() => '${super.toString()} : $someValue';
}

You can enter expressions in the debugger like _currentState == _eventManager I don't know how to open the Expressions view in the Eclipse Dart plugin though.
I don't know about the id. About the "hash" in your questions title. A hash isn't guarantied to be unique.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Where I have to put expression in eclipse to evaluate it? There is 'inspector' view but 'print it' option is disabled. – kolar Mar 05 '15 at 20:50
  • 1
    I don't know the Eclipse plugin but in DartEditor (Eclipse based) there is a toolbar in the Debugger view named "Show expressions" which allows you to enter expressions. – Günter Zöchbauer Mar 05 '15 at 20:52
  • Ok, I have found it in eclipse, it is called Expressions View. Thanks! – kolar Mar 05 '15 at 20:55
1

The id is the default way for Eclipse to help you distinguish objects. It's a number assigned by Eclipse itself the first time it had to present that particular object to you, and if it later shows you the same object again, it will have the same id. It's purely for debugging, and exactly allows you to see whether two references are to the same object or to different objects, even if both have a toString returning just Instance of "StateManager".

So to answer the two remaining questions: You use the id to see if objects are identical, and you don't need to override toString.

See also: What is the id=xxx next to variable entries in the Eclipse Debugger

Community
  • 1
  • 1
lrn
  • 64,680
  • 7
  • 105
  • 121
  • As far as I can see it's not true, `id` of one object changes during debugging in dart. I have checked it by printing object hash in `toString'. And this is why I have created this question. – kolar Mar 06 '15 at 08:09
  • If that is the case, it is probably a bug in the Dart Eclipse plugin. The `id` should not change for an object instance as long as the instance is alive. It may change between different runs of the same program, or (possibly) if the debugger is detached and reattached to the same program, if that is even possible. The hash code of objects are not guaranteed to be unique, so it is possible for different objects to have the same hash value. If the objects are equal (according to `operator==`) the has codes *should* be equal. Even `identityHashCode` doesn't guarantee different values. – lrn Mar 06 '15 at 11:31