2

If I tell Netbeans to automatically generate code, let's say a constructor, I want all parameters to use the final modifier.

Currently:

public Person(String firstName, String lastName, String address) {
  // ...
}

What I want:

public Person(final String firstName, final String lastName, final String address) {
  // ...
}

Is it possible to change that in Netbeans, and if yes: where would I do that?

TwoThe
  • 13,879
  • 6
  • 30
  • 54

1 Answers1

1

That doesn't seem to be possible out of the box. I have looked for "easy" configuration options for any of the auto-generated methods (constructor, get/setters, toString() etc) in (NetBeans 8.0.2):

  1. Tools -> Options -> Editor -> Code Templates -> Java
  2. Tools -> Options -> Editor -> Code Completion -> Java
  3. Tools -> Templates -> Java
  4. NetBeans Java Editor reference documentation

If such functionality cannot be found in any of the above, it's safe to assume it doesn't exist.

In the NetBeans documentation here you can see an example of how to extend NetBeans with a custom code generator. That's one viable alternative, but it involves writing Java code that will generate Java code.

In summary, create a new NetBeans module :
File -> New Project -> NetBeans Modules -> Module

and then a custom generator by right-clicking on the module and
New -> Other -> Module Development -> Code Generator

You will have to go through NetBeans' source code for the current method that generates constructors.

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82