Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of the Java keyword const [duplicate]

Tags:

java

Possible Duplicate:
Why is there no Constant keyword in Java?

I recently started developing in Java and I was wondering why the keyword const wasn't implemented and you had to use a rather long constant definition in a class:

protected static final String VALIDATION_ERROR = "validationError";

Instead of the expected way

const VALIDATION_ERROR = "validationError"

Is there anyone who can point me out why you have to use (or hasn't made it in the current syntax) the former instead of the later since the later is assuming the former?

like image 630
JF Dion Avatar asked Oct 11 '12 13:10

JF Dion


2 Answers

In java final == const

The other keywords (protected & static) are doing things in addition to defining the constant (defining the scope)

like image 103
Colin D Avatar answered Oct 30 '22 15:10

Colin D


final String is enough, protected and static showing the scope of the constant.

like image 28
greatmajestics Avatar answered Oct 30 '22 14:10

greatmajestics