Search code examples
javanetbeanssnapshotcode-templates

How use 'code template' in 'select templates'


Example:

I enter n and press the shortcut tab. I get Object object = new Object ();. All is well. 'select templates' is first position "Object". I want to use the 'code template' to replace it with "String". I enter St and press the shortcut tab. Expected result: String string = new String(); The result: St st = new St(); + 'select templates' moves to the 2nd position.

I seem to understand why this is happening, but I want to use 'code template' in 'select templates'.

Please tell me who faced this situation and how you solved it.

p.s. perhaps I do not correctly call the term 'select templates'. Please correct me if this is so.


Solution

  • I enter St and press the shortcut tab. Expected result: String string = new String(); The result: St st = new St();

    The actual result is the correct behavior because you specified that you want to use the value St.

    The problem is arising because there are multiple valid possibilities that start with St such as StrictMath or String or StringBuffer. NetBeans can't know which of those values you want to use, and by pressing tab you are telling NetBeans that you specifically want to use the value St.

    Resolve this as follows:

    • Enter St and then press Control/Space.
    • NetBeans will list the available options that start with St in a dropdown menu.

    controlSpace

    • Scroll down the list, select the entry for String and press Enter.
    • Netbeans will then generate the code you want: String string = new String();