¿No me deja inicializar una constante final int?
Frecuentes
Visto 779 veces
-1
I need to initialize a constant int for this program but it's giving me the error "Syntax error on token "NO_VALUE", delete this token", but "NO_VALUE" is supposed to be the name of the int.
Here is the code where I try to initialize it
public class DayOfWeek {
int myMonth, myDayOfMonth, myYear, myAdjustment, numericDayOfWeek;
public final int constant NO_VALUE = -1;
1 Respuestas
4
Eliminar el inválido constant
keyword (and add static
) to produce a constant
public static final int NO_VALUE = -1;
Echa un vistazo a la palabras clave disponibles
También echa un vistazo a esto https://www.youtube.com/watch?v=xB-eutXNUMXJtA&feature=youtu.be
contestado el 23 de mayo de 17 a las 13:05
My classmate told me this was not the same as constant though? Also the professor said initialize it as a constant, and this is java - Bob Marley
Ok I changed it to public static final but it is still giving me this error; Syntax error on token "NO_VALUE", delete this token - Bob Marley
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas java int constants or haz tu propia pregunta.
The compiler goes on compiling as long as the text so far could be the prefix of some valid program, and then reports an error on the next token. "constant" is a valid Java identifier so "NO_VALUE" is the token that forces the compiler to report an error. Often, the real problem is a few tokens back from the reported error. - Patricia Shanahan