A2oz

What is the shortcut to override methods in IntelliJ?

Published in Programming 1 min read

IntelliJ IDEA does not have a dedicated shortcut for overriding methods. However, you can leverage the following shortcut to quickly implement a method override:

  • Alt+Insert (or Ctrl+Insert on Windows/Linux): This shortcut brings up the "Generate" menu, which includes options for overriding methods.

Once the "Generate" menu appears, simply select the method you want to override, and IntelliJ will automatically generate the necessary code.

Example:

Let's say you have a class MyClass that inherits from the class ParentClass. ParentClass has a method doSomething(). To override this method in MyClass, you can follow these steps:

  1. Open the MyClass file in IntelliJ.
  2. Place your cursor inside the class body.
  3. Press Alt+Insert (or Ctrl+Insert).
  4. Select Override Methods.
  5. Choose doSomething() from the list of methods available for overriding.

IntelliJ will then create a new method doSomething() in MyClass with the correct signature, ready for you to implement.

Related Articles