• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

const syntax.

 
Asaf Karass
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello.
what is the const syntax?
I want to put a int array as a const.
where in the JavaDoc can I find this stuff?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Asaf,
The syntax for a constant in Java is final so you would do something like:

To make a constant called CONSTANT_NUM for your class, and set it to 10. (static final makes it a constant for every object in the class, and final by itself makes it constant just for the current object. That means you can leave out the value and assign it a value in the class constructor. Then you can't change it afterwards. That means you can make each object have a different constant if you wanted. Pretty cool , huh? )
You can find this in the JLS in section 8.3.1.2, but I would really advise getting something a little more readable as a language reference. Look in the JavaRanch Bunkhouse for some suggestions.
HTH,
-Nate
[This message has been edited by Nathan Pruett (edited March 16, 2001).]
 
Asaf Karass
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will this work for a final int array :
int m = 2;
final int array[] = new int[500];
array[1] = m;

??
btw - I know what static is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic