Realize Objects.hashCode() and Objects.equals(...) implementation of Java 7 within eclipse [message #1082465] |
Thu, 08 August 2013 15:54 |
Peter Shaw 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 |
Ed Merks Messages: 33218 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/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08284 seconds