-3

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?

Ismail Yavuz
  • 6,727
  • 6
  • 29
  • 50
  • 5
    `toString` is supposed to be a string representation of a specific instance of your class - why would you want static fields to be included? – assylias Jun 25 '14 at 10:33
  • I've a properties class. All are static fields. Actually I've no instance of it. And I want to log those properties. This is a Q&A site right? – Ismail Yavuz Jun 25 '14 at 11:37
  • Yes it's a Q&A site but your question does not really make sense - so it seems that you will need to write it yourself (I don't think any IDEs would auto-include static fields in a `toString` method). – assylias Jun 25 '14 at 11:40
  • 2
    "Actually I've no instance of it." **Then it is impossible to call the toString() method, which is an instance method.** – Boann Jun 25 '14 at 11:45

2 Answers2

1

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.

ssedano
  • 8,322
  • 9
  • 60
  • 98
1

The easiest way that i could find for my case:

1-) replace " static" with ""

2-) Source -> generate toString with all fields that you want

3-) than again replace "public " (two spaces) public static "

That's it!

Ismail Yavuz
  • 6,727
  • 6
  • 29
  • 50