javaintellij-ideagettergetter-setter

Can IntelliJ generate getters without the "get" prefix?


IntelliJ has the cool feature to generate Java getters. For example, for a field private final String foo, it will generate a getter getFoo().

Is there any way I can configure IntelliJ to generate getters in the format String foo()? I am working mainly with immutable objects and prefer this syntax.


Solution

  • Neat question! Just to clarify @Danny Dan's answer since IntelliJ 15 has been released...

    To set this up:

    Example Template: fluent-getter

     public ##
     #if($field.modifierStatic)
       static ##
     #end
     $field.type ##
     ${field.name}() {
       return $field.name;
     }
    

    Why would you want to do this?

    Checkout Implementing Domain-Driven Design:

    The simple but effective approach to object design keeps the Value Object faithful to the Ubiquitous Language. The use of getValuePercentage() is a technical computer statement, but valuePercentage() is a fluent human-readable language expression.