Tuesday, November 23, 2010

How to create a new object in NetBeans

Another useful java code template is newo, that expands to the following:
Object obj = new Object();
As behind the curtains the expression is

${TYPE default="Object"} ${OBJ newVarName default="obj"} = new ${TYPE}(${cursor});
all you have to do is change the type and note how the IDE at the same time changes the name of the variable setting the first letter in lowercase, e.g. if you hit newo TAB MyObject the result will be
MyObject myObject = new MyObject();
Neat and clean :-)

2 comments:

Kris Scorup said...

That's nice. I've been using "n <tab>" for quite a while, but it doesn't change the variable name.

Unknown said...

Great! it works perfectly on my NetBeans 6.9.1! Thanks for the hint!