调试dart app时变量的唯一id(哈希?)

时间:2015-03-05 20:34:16

标签: eclipse dart

eclipse dart插件在'变量'视图中显示如下: enter image description here

'value'列中'id'的含义是什么? 'id'是独一无二的吗?如何在调试期间确定两个实例是否相同?我是否需要在所有类中覆盖toString()?

2 个答案:

答案 0 :(得分:1)

当然,您可以在类中覆盖toString。

class MyClass {
  String someValue = 15;

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

您可以在调试器中输入表达式,如_currentState == _eventManager我不知道如何在Eclipse Dart插件中打开表达式视图。
我不知道id。 关于问题标题中的“哈希”。哈希不保证是唯一的。

答案 1 :(得分:1)

id是Eclipse帮助您区分对象的默认方式。它是Eclipse本身第一次向您呈现该特定对象时分配的编号,如果它稍后再次向您显示相同的对象,则它将具有相同的ID。它纯粹用于调试,并且确切地允许您查看两个引用是属于同一对象还是属于不同对象,即使两者都有toString只返回Instance of "StateManager"

回答其余两个问题:您使用id查看对象是否相同,并且您不需要覆盖toString

另请参阅:What is the id=xxx next to variable entries in the Eclipse Debugger