Search code examples
javaintellij-ideaintellij-plugin

Intellij generate static final fields


in a project I need to create many fields with the same type and access modifier
is there a way in intellij to generate public static final fields?


Solution

  • Type all names on separate lines, select the lines and do a regex replace for the selection.

    (\w+)
    
    public static final XYZ $1 = new XYZ("$1");
    

    Being comfortable with regex in editing belongs to a developer's basic tools.

    By the way interfaces do not need public static final; that is implicit.