Ändern Sie die Foo.BA * Variablendeklarationen, um Initialisierer zu haben, die kompilierungszeitkonstante Ausdrücke sind. It just got me wondering i create a new android project and used a switch-case statement and work fine.. – HeartlessArchangel Feb 1 '12 at 10:13 See definition of Values.java:9: error: constant expression required Yes, as somebody said yesterday, a Character object doesn't count as a constant expression. In my case the DataType represents an Object type, so rather than refactoring the switch to use Enum's, I plan to create an interface and move the logic with in the case statements to the object, allowing be to remove the switch statements from the code. Java switch statement: Constant expression required, but it IS constant (6) I understand that the compiler needs the expression to be known at compile time to compile a switch, but why isn't Foo.BA_ constant? Yes, you can To clarify, an enum constant is not a constant expression as defined by the Java Language Speicification 3rd Edition. Während sie aus der Perspektive eines beliebigen Codes konstant sind, der ausgeführt wird, nachdem die Felder initialisiert worden sind, sind sie keine Wir rufen eine Variable vom primitiven Typ oder Typ String auf, die final ist und mit einem Konstanten-Ausdruck zur Kompilierungszeit (§15.28) eine konstante Variable initialisiert wird. Android, constant, error, EXPRESSION, java, Switch, TIP, 안드로이드, 자바 그 때 간혹 "constant expression required" 라는 에러를 마주치는 경우가 있다. – emeraldjava Nov 26 '10 at 10:14 But then again, the error messages have nothing to do with the new 'DataType' class, though, so perhaps I'm misinferring the code that's causing the compile errors. In Ihrem Beispiel haben die Variablen Foo.BA * keine Initialisierer und sind daher nicht als "konstante Variablen" zu verstehen. because Android Studio complaints Constant expression required. I understand that the compiler needs the expression to be known at compile time to compile a switch, but why isn’t Foo.BA_ constant? Betrachten Sie den folgenden gültigen Code: Uses for Constant Expressions. Als ich mit diesem Problem konfrontiert wurde, habe ich einfach eine Ich habe diesen Fehler auf Android erhalten, und meine Lösung war nur zu verwenden: Um das Problem zu lösen, sollten Sie die Variable (in diesem Fall) auf int setzen. adita malviya wrote: Compiler is treating a,b and c as variable but there you need a constant expression for the data type you provide in your switch label.
Should it not be case DataType.INTEGER_VALUE: that should be in the compiler error?Based on what you've shows so far, I can't see what the problem is; this should work based on what I *assume* you're doing in e.g. In my case the DataType represents an Object type, so rather than refactoring the switch to use Enum's, I plan to create an interface and move the logic with in the case statements to the object, allowing be to remove the switch statements from the code. In my case the DataType represents an Object type, so rather than refactoring the switch to Die Lösung ist einfach. Während sie aus der Perspektive eines beliebigen Codes konstant sind, der ausgeführt wird, nachdem die Felder initialisiert worden sind, sind sie keine Wir rufen eine Variable vom primitiven Typ oder Typ String auf, die final ist und mit einem Konstanten-Ausdruck zur Kompilierungszeit (§15.28) eine konstante Variable initialisiert wird.

But I wouldn't worry. 问题描述 今天在代码中想对Java switch case 和枚举类型 Enum 对象进行联合 使用 ,但发现有Eclipse中异常提示信息:case expression s must be constant expression s,导致编译始终过不去。 See JLS 15.28 for what constitutes a constant expression. Als ich mit diesem Problem konfrontiert wurde, habe ich einfach eine Ich habe diesen Fehler auf Android erhalten, und meine Lösung war nur zu verwenden: Um das Problem zu lösen, sollten Sie die Variable (in diesem Fall) auf int setzen. mehrere - java switch constant expression required enum Java switch-Anweisung: Konstante Ausdruck erforderlich, aber es ist konstant (6) Java switch case 枚举enum报错:case expressions must be constant expressions 1. I don't want to be forced to change all the switches yet, so its there a clean work around?I don't think there is any workaround, apart for a large-scale change to all of the switch statements. i change my switch-case statement to else-if statement.. Die Lösung ist einfach.


Well it's not - a method call is never a constant expression. mehrere - java switch constant expression required enum Java switch-Anweisung: Konstante Ausdruck erforderlich, aber es ist konstant (6)

La Petite Fringale Brezolles, Appartement T2 Chambéry, à Vendre, B&B HOTEL3,9(564)À 3,9 km48 €, Hagoromo Ôtsutsuki Susanoo, Neige Alsace 2019, Remede Passerelle 2020, Triple Frontière Age, Condition ? : Java, Nouveau Télésiège Grand‑Bornand, Vpn Auto Pro, Ter Arènes Colomiers 2019, Dans La Peau De John Malkovich Acteurs, Storio Max Xl Fiche Technique, Carte Pêche Savoie 2020, Parcours Vélo Lyon Miribel, Genma Shiranui Death, Je Publierai Ou Je Publierais, Tour Du Désert De Platé, Vendeur De Vin Synonyme, Planeur Rc Tchèque, Sentier Des Bisses Du Val Des Dix, Interstellar Musique Orgue, Budget Tour D'europe En Van, Camping Du Château, Fermer Une Centrale Nucléaire, Parc Des Franchises Grillades, React Style Background Image, Typescript Contains String, 1 Timothée 2 5 6, Agence Immobilière Vallouise, Jeux En Forêt, Evolution Du Tourisme à Venise, Foodora Frais De Livraison, Chanaz, Savoie Photos, Lac Vert Savoie, Appel Fonction Javascript Onclick,