Deepak Gupta
Deepak Gupta

Reputation: 1075

what is the shortcut to auto generate hashcode() and equals()?

I am working on a project (Java) and created an Object with a large number of variables. Since I am planning to add hashcode() and equals(). Is there a short cut in Eclipse to automatically generate hashcode() and equals() in a given class ?

Upvotes: 5

Views: 4686

Answers (4)

Dr.jacky
Dr.jacky

Reputation: 3547

For Mac users: Command + N (⌘N)

IDE: Android Studio

[Source: https://www.jetbrains.com/help/idea/generating-code.html#generate-equals-hashcode ]

Upvotes: 1

Deepak Gupta
Deepak Gupta

Reputation: 1075

Ways to Generate hashcode() and equals() Method -

1) Press Alt + Shift + S + H
2) Right click -> Source -> Generate hashcode() and equals() Method
3) Go to Source menu -> Generate hashcode() and equals() Method
4) Go to Windows menu -> Preferences -> General -> Keys (Write Generate hashcode() and equals() Method on text field)

Upvotes: 4

Aniket Kulkarni
Aniket Kulkarni

Reputation: 12983

  • Press ALT + SHIFT + S, H.

Another option is

  • Go to Window --> Preferences --> Click on General --> Keys. You will see

enter image description here

Now, type "hash" and you can set command of your choice.

Some useful shortcuts are

  1. 93 shortcuts
  2. more shortcuts

Upvotes: 1

Thanigai Arasu
Thanigai Arasu

Reputation: 413

Is there a short cut in Eclipse to automatically generate hashcode() and equals() in a given class

Yes, Right click on the variable and source-> Generate hashcode() and equals().

Upvotes: 0

Related Questions