What is the most annoying thing for programmers? Look under:
Repeat, repeat , repeat. important thing to say three times!! For example, when creating a thread's inner class:
Thread t = new Thread (new Runnable () {public void run () { //TODO }});
There's always a way to be a programmer, haha. Java has a template this thing, very convenient.
Every time we hand lazy, do not always have to hand the cheap press alt+/ key, to get code hints? Ha ha.
Well, there's no template for creating anonymous thread classes in the Eclipse Java template! (At least I didn't find it).
The programmer's famous assertion is: create it without it !
First, we need to know how template templates are written. The first step: see how to write in Eclipse.
For the For Loop example, open the eclipse->reference->template and think of the following:
To parse the template statement:
${index} does not mean that we often knock on the I, J, K//${array} Of course the name of the array to be indexed, it will automatically search for the name of the array you want to traverse oh!for (int ${index} = 0; ${index} < ${array}.lengt H ${index}++) { //${cursor} is the cursor Location code ${line_selection}${cursor}}
In fact, the template is similar to the shoe code! Just have a set of rules to represent variables, and this set of rules is in Eclipse help
Inside. Road (look):
There are too many things in it, we pick a few common, understand the wording, almost understand! Recommended for | foreach | Try
Homemade Template
Said so much, now to come to the actual combat below! To create a thread anonymous inner class as an example, long ago to see you are not pleasing to the eye, haha!
First create a new template in Eclipse (press the new key), enter the template name, the TD is good, pay attention to not and other repetition Oh!
Thread ${thread:newname (thread)} = new Thread (new Runnable () { @Override public void Run () { //todo ${ Line_selection}${cursor}} );
Look at the effect: enter TD and Press alt+/ :
O! Isn't it simple! No more worrying about repetition!
Here is a common example of the pattern template, the end of it! ^_^
Private ${type} () {}private final static ${type} instance = new ${type} ();p ublic static ${type} getinstance () {return Instan CE;}
Look at the effect:
How to write a Java template