Java switch statement: Constant expression required, but it IS constant

前端 未结 13 1723
予麋鹿
予麋鹿 2020-11-22 10:42

So, I am working on this class that has a few static constants:

public abstract class Foo {
    ...
    public static final int BAR;
    public static final          


        
13条回答
  •  庸人自扰
    2020-11-22 11:20

    In my case, I was getting this exception because

    switch (tipoWebServ) {
                                case VariablesKmDialog.OBTENER_KM:
                                    resultObtenerKm(result);
                                    break;
                                case var.MODIFICAR_KM:
                                    resultModificarKm(result);
                                    break;
                            }
    

    in the second case I was calling the constant from the instance var.MODIFICAR_KM: but I should use VariablesKmDialog.OBTENER_KM directly from the class.

提交回复
热议问题