Skip to content

Instantly share code, notes, and snippets.

@zzt93
Last active August 29, 2015 14:14
Show Gist options
  • Save zzt93/08d8d302bc8e5f1006b1 to your computer and use it in GitHub Desktop.
Save zzt93/08d8d302bc8e5f1006b1 to your computer and use it in GitHub Desktop.
Java constant - final
import java.util.Random;
/**
* Created by zzt on 1/24/15.
*/
public class Const_java {
private static Random rand = new Random(47);
// can be compile-time constants:
private final int valueOne = 9;
private static final int VALUE_TWO = 99;
// typical public constant:
public static final int VALUE_THREE = 39;
// can also be run-time constants:
private final int i4 = rand.nextInt(20);
static final int INT_5 = rand.nextInt(20);
// a final reference
private final String s1 = new String("s1");
// Arrays:
private final int[] a = { 1, 2, 3, 4, 5, 6 };
public static void main(String[] args) {
Const_java const_java = new Const_java();
//Const_java.INT_5++;
// error
//const_java.s1 = "asd";
//error
const_java.s1.concat("asd");
const_java.a[0] = 1;
//const_java.a = new int[9];
//error
}
}
Java constant - final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment