Search code examples
javaeclipsetostringmyeclipse

Why Eclipse generate toString includes only non-static fields?


I want to use in myEclipse 10.1 (probably same issue in eclipse)

Source-> generate toString to build toString method automatically.

However there is no variables which has static identifier in FIELDS list.

Why?

And how can i represent also static fields in toString automatically?


Solution

  • The toString() method is related to the state of the instance (same as hashCode and equals). Static fields do not belong to the instance, they belong to the class, thus do not belong, strictly speaking, to the instance state.

    You can edit the toString() template in the dialog. At the Generated code there is String format in the drop down there is the default and an Edit... button.