Idea is the development tool we use most. This tool has a special awesome feature: Live Template. After this function is mastered, the speed of the code will be at least quadrupled. Let me show you what this thing can do. Create a liveTemplate.java class in idea as follows:
Type PSVM at the cursor position, then press Tab or Enter, and the magic happens. The main method appears momentarily.
This is the function of live Template in IDEA, commonly known as template function. You can create a piece of code as a template, then define a short name for the template, and then enter the name of the template in the code with TAB or Enter key, you can instantly introduce the template code snippet into the current code. Greatly improved the development efficiency. Let’s take a look at some of the common templates that you’re going to take a moment to memorize. 1. Live Tempalte
1.1, ifn
if (args == null) {}Copy the code
1.2, PSVM
public static void main(String[] args) {}Copy the code
1.3, fori
for (int i = 0; i < ; i++) {
}
Copy the code
1.4, inn
if(args ! =null) {}Copy the code
1.5, inst
if (args instanceof Object) {
Object o = (Object) args;
}
Copy the code
1.6, toar
List<String> list = newArrayList<>(); Then press toar to get List<String> List =new ArrayList<>();
String[] strings = list.toArray(new String[list.size()]);
Copy the code
1.7, PRSF
private static final
Copy the code
1.8, PSF
public static final
Copy the code
1.9, psfi
public static final int
Copy the code
1.10, PSFS
public static final String
Copy the code
1.11, THR
throw new
Copy the code
In fact, there are many, such as Android, SQL, HTML, all have, you can go to have a look
File->Settings->live tempalte
Copy the code
3. Customize the Live TemplateIdea comes with some common templates, but sometimes we also want to customize some of our own more common templates, so how to operate?3.1, File – > Settings – > Live template
3.2. Add a groupClick on “+” and select “Template Group”. Let’s call the Group my, you can call it whatever you want
3.3. Add Live TemplatesAdd a template under our my group as follows
3.4. Set template information
- Abbreviation (indented name) : that is, after the code type PSSD press the shortcut key to generate private static String var
- Edit variables: Edit variables, including the sequence and function of variables, as described in the remarks below
- Description (Comment) : Comment the template function
- Template text: x x is the variable, END is the variable, that is, the last position of the cursor
- Specify what file and under what circumstances to use. Generally, Java is selected by default
- Options: Enter PSSD and press Enter or Tab to generate a template. Authors generally use the Tab key, on the one hand to prevent conflicts with the native template, on the other hand with the shell shortcut key
- Reformate According to Style: Automatic code formatting. Unchecked code does not automatically indent newlines
VAR1 and VAR2 do not represent the input order. The input order of variables is in Edit variables and can be changed by adjusting the upper and lower order. For the use of advanced variables, refer to the next section or the official documentation
www.jetbrains.com/help/idea/e…
3.5. Let’s define a try-catch-finnaly shortcut
Then in the code input “TCF + TAB key”, instantly appear the following code, is not special cool
try{}catch (Exception e) {
} finally{}Copy the code