Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse
icon14.gif  Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1082465] Thu, 08 August 2013 15:54 Go to next message
Peter ShawFriend
Messages: 4
Registered: August 2013
Junior Member
Hi everybody,

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
Re: Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1082863 is a reply to message #1082465] Fri, 09 August 2013 05:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Peter,

You might be better off asking on the eclipse.tools.jdt forum or opening
a bugzilla enhancement request for JDT.


On 08/08/2013 9:17 PM, Peter Shaw wrote:
> Hi everybody,
>
> 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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1084924 is a reply to message #1082863] Mon, 12 August 2013 08:14 Go to previous messageGo to next message
Peter ShawFriend
Messages: 4
Registered: August 2013
Junior Member
Ed,

thank you for your answer. Is it possible to "move" the question to the more appropriate forum? I don't want to duplicate it and linking here seems to be a bad idea too.
Re: Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1084931 is a reply to message #1084924] Mon, 12 August 2013 08:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Peter,

No, it can't be moved. With the web forum it's not even possible to
reply to more than one newsgroup to copy it that way. With NNTP that's
possible.

On 12/08/2013 10:14 AM, Peter Shaw wrote:
> Ed,
>
> thank you for your answer. Is it possible to "move" the question to
> the more appropriate forum? I don't want to duplicate it and linking
> here seems to be a bad idea too.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1084936 is a reply to message #1084931] Mon, 12 August 2013 08:33 Go to previous message
Peter ShawFriend
Messages: 4
Registered: August 2013
Junior Member
Thank you Ed, I will rephrase the question and link it back here than.
Previous Topic:Autosave like Google Docs
Next Topic:Window Builder
Goto Forum:
  


Current Time: Fri Apr 19 00:47:54 GMT 2024

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

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

Back to the top