John
John

Reputation: 1189

Defining as constants in Java

list.loadRequestParms(request, 'a', 20);

This method takes three parameters

  1. a request object.
  2. a char
  3. an integer

Now how to define these as constants somewhere and use it in this method.

Upvotes: 0

Views: 447

Answers (3)

Jungle Hunter
Jungle Hunter

Reputation: 7285

Constants? You mean variables that don't change and are final? Same copy of which lasts all throughout, i.e. are static? And they can also be publicly accessible.

http://www.devx.com/tips/Tip/12829

public class MaxUnits {
   public static final int MAX_UNITS = 25;
}

Upvotes: 0

Codemwnci
Codemwnci

Reputation: 54934

I think I understand what you mean, but more detail would have been useful.

static final Request MY_REQUEST_CONST = someRequest;
static final char MY_A_CONST = 'a';
static final int MY_INT_CONST = 20;

list.loadRequestParms(MY_REQUEST_CONST, MY_A_CONST, MY_INT_CONST);

Some things to note. A constant in Java is created by the final static keywords. Convention suggests that constant variable names are uppercase.

Upvotes: 3

Oded
Oded

Reputation: 499262

How to define constants in Java - tutorial.

Passing parameters in Java - an article.

Upvotes: 2

Related Questions