Sand
Sand

Reputation: 428

Java code conventions: Using 'default' as a variable name

I would like to use 'default' as a variable name. Is there a code convention (like class -> clazz) that suggests how I should name the variable?

Upvotes: 13

Views: 6597

Answers (2)

towe75
towe75

Reputation: 1470

One more thing: if it is a fixed value - a constant instead of a variable - make it final or even static final/public static final and keep it as class member instead of a local variable. You should write constants upper case.

Example

public class MyClass {

  public static final String DEFAULT_NAME = "MyApplication";

  public String name;

  public MyClass() {
      this.name = DEFAULT_NAME;
  }

}

Upvotes: 2

Joachim Sauer
Joachim Sauer

Reputation: 308001

I usually add a term that indicates for what it is the default. So I'd use defaultName or defaultPermission or possibly defaultValue (only if the meaning is clear for the context).

Upvotes: 18

Related Questions