[IntelliJ] Override a method of a superclass2021. 7. 28. 10:40
Override methods of a superclass
Last modified: 08 March 2021
You can override any method of a parent class by generating necessary code from a predefined template. IntelliJ IDEA creates a stub that contains a call to the method of the superclass, leaving the developer with the task of providing some meaningful source code in the method's body.
Override a method of a superclass
- On the Code menu, click Override methods Ctrl+O. Alternatively, you can right-click anywhere in the class file, then click Generate Alt+Insert, and select Override methods.
- Select the methods to override (hold the Shift or Ctrl key to perform a multiple select). The list does not include the methods that are already overridden or cannot be accessed from the current subclass.If necessary, select the Copy JavaDoc checkbox to insert JavaDoc comments for the overridden methods.
- If necessary, select the Insert @Override checkbox to insert the @Override annotation.
- Click OK and provide the source code for the method body.
- Hover over the icon in the gutter to view the name of the base class. Click it to open the overridden method declaration.
Change the method body
The code template used for overriding methods (Overridden method body) accepts predefined template variables from the File Header include template (such as ${USER}, ${DATE}, and so on).
For example, consider the following code template:
#if ( $RETURN_TYPE != "void" )return $DEFAULT_RETURN_VALUE;#end // TODO ($USER, $DATE):To change the body of an implemented method, use File | Settings - Editor - File and Code Templates.
Copied!
Provided that the overridden class contains two methods, this template expands into the following code:
public void breathe() { // TODO (wombat, 9/21/12): To change the method body, use Settings - Editor - File and Code Templates. } public void eat() { // TODO (wombat, 9/21/12): To change the method body, use Settings - Editor - File and Code Templates. }
Copied!
Was this page helpful?
YesNo
출처: https://www.jetbrains.com/help/idea/overriding-methods-of-a-superclass.html#file_template
'Development > IDE, Github' 카테고리의 다른 글
[IntelliJ] Intellij Git 쉽게 사용하기!!! (0) | 2021.08.06 |
---|---|
[IntelliJ] Top 20 Navigation Features in IntelliJ IDEA (0) | 2021.07.28 |
[IntelliJ] IntelliJ 메모리 설정(IntelliJ 메모리 늘리기) (0) | 2021.07.12 |
[Markdown] Markdown 마크다운 사용법, 문법 (0) | 2021.06.28 |
[IntelliJ] IntelliJ 단축키(Shortcut Key) 설정법 (0) | 2021.06.11 |