Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse
Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1084942] Mon, 12 August 2013 08:36
Peter ShawFriend
Messages: 4
Registered: August 2013
Junior Member
Hi everybody,

I already asked this question here in this part of the eclipse forum "m/1084936/#msg_1084936", but I was told to ask again here, since it is not possible to "move" the question. Sorry for the "double post". If some admin is willing, I would be glad to see the other post deleted to reduce confusion.

Now to my question:

eclipse is a great help when it comes to generating equals(...) and hashCode(). Just hit SHIFT+ALT+S and h afterwards and you're done after pressing Enter.

The same holds for toString(). Same shortcut as above, but use s instead of h.

But unlike for equals(...) and hashCode(), eclipse offers the possibility to customize toString().

Why is there no possibility to do so for equals() and hashCode(). Since Java 7 there is the awesome Objects.hashCode() and Objects.equals(...) implementation which reduces a lot of the boyler plate code.

I tried to realize the implementation by eclipse templates, but unfortunately there is no way to gather all "instance variables" by the template language of eclipse. There is a way using reflection but someone told me this is a bad solution - unfortunately I don't remember the arguments.

Therefor I'd like to ask:

1. Is it possible to teach eclipse to use the implemetations of Objects.hashCode() and Objects.equals(...)? Maybe without losing the SHIFT+ALT+S -> h -> Enter way of doing this? If yes on which version and how?

2. Is it somehow realizable by a template, which I couldn't have figured out? What would such a template look like?

3. If there is no native way to do so, is it on the agenda of the developers of eclipse? Or are there other ways of realizing this?

I believe that a significant amount of eclipse user would be interested in this, since it is quite a neat thing to have. I assume if you read this you will know what I am talking about, but if not, just scan through this page: javaworld.com/community/node/8014

Thank you for your attention!

Best regards
Peter
Previous Topic:Eclipse Kepler 64-bit is crashing
Next Topic:Help Needed in getting the model Object of TextEditor
Goto Forum:
  


Current Time: Thu Apr 25 07:02:07 GMT 2024

Powered by FUDForum. Page generated in 0.02615 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top