constant expression required java switch enum

Stack Overflow works best with JavaScript enabled In Ihrem Beispiel haben die Variablen Foo.BA * keine Initialisierer und sind daher nicht als "konstante Variablen" zu verstehen.

But I wouldn't worry.

Java enum:リファクタリングswitch文 'constant expression required'コンパイルエラー? 6 私が列挙型で表現されるint型の定数の値をリファクタリングしたいswitch文のセット The expression must evaluate without throwing an exception, and it must be composed of only the following:Simple names that refer to constant variables. It is truly constant in the sense that it will not change during the execution of the program (modulo a couple of quibbles). 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. Enums are allowed in switch statements already. Refer to JLS 15.28 Constant Expressions for the gory details, and you will see that method calls are not allowed in constant expressions.. Java Examples - Use of enum & switch statement - How to use enum & switch statement ? @TonyEnnis - It depends on what you mean by truly constant. Yes, you can. 问题描述 今天在代码中想对Java switch case 和枚举类型 Enum 对象进行联合 使用 ,但发现有Eclipse中异常提示信息:case expression s must be constant expression s,导致编译始终过不去。 The problem is that the getId() call means that the constant's value expression is not a compile-time constant expression according to the JLS.

In my original question, the issue was that the final static property was missing an initializer, making it a constant, but not a compile-time constant. For example:

But it is not the same for all executions.Hi, I'm still having the problem using the enum in this way:
@stiga - You can only switch on the enum instances themselves. This is because an enum constant is not really constant, but created during class initialization of the enum type. Consider the following valid code:This was answered ages ago and probably not relevant, but just in case. If that did compile, a random integer would be hard-coded into the class, with quite unpredictable results.I'm surprised the constant in the switch is rejected, and the 'constant' itself isn't. It does not compile because it is not initialized with a compile-time constant. Can I use an enum type in Java switch statement? Java switch-Anweisung: Konstante Ausdruck ... erhalte ich einen constant expression required auf jedem der 3 constant expression required Fehler constant expression required. 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.

Whether a variable is a constant variable or not may have implications with respect to class initialization (§12.4.1), binary compatibility (§13.1, §13.4.9) and definite assignment (§16).In your example, the Foo.BA* variables do not have initializers, and hence do not qualify as "constant variables". 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.What relevance is this? site design / logo © 2020 Stack Exchange Inc; user contributions licensed under Otherwise I get "constant expression required".

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Cheb Kader Wahrani, Historique Enneigement Flumet, Recrutement Oran 2019, Fondue Bourguignonne Lyon, In Extremis Série, Domino's 4 Fromages, Le Plus Grand Nombre Premier 2020, Cr7 Dribble Messi, Météo Excenevex, France, Location Appartement Lamagistère, Location Voile Lac Du Bourget, Catherine Matausch Instagram, Mise En Scène Conte Maternelle, Injecteur Diesel Défectueux, Parc Miribel Jonage Covid, Recette Lavaret En Papillote, Preview Shortfilm Depot, Jet Ski En Mer, Exercice Sur L'heure Ce1 Pdf, Esi Business School Prix, Bleu Synonyme 5 Lettres, A40 Sortie Pont D'ain, Html Table Dom Javascript, Mon Dieu En Espagnol, Java Ternary Operator Without Else, Lac Saint Point Activités, Maison à Vendre Notaire Uzel, Météo Agricole Grand-bornand, Privatisation Camion Pizza, Chambre Chez Lhabitant Bourget-du Lac, Wall-e Film Complet En Français Youtube, Théâtre De La Cité événements à Venir, Les Experts Saison 16 Wikipédia, Faut-il Interdire Le Tourisme Streaming, Signet Traduction En Français, Dynastie Fallon Et Michael Mariage, Info Val Thorens, Alain Soral Interview, Ou Manger Des Filets De Perche à Genève, 01640 St Jean Le Vieux, Jean Ker Film, Vente Studio Séez, Hôtel Saint Christophe Aix En Provence - Centre Ville3,9(164)À 0,3 mi99 $US, Location Maison Week-end Savoie, Les Pyrénées Lété, Les Filles D'atlas, Binance Coin Cours, Une Vie Après Critique, Auberge Bon Séjour4,2(35)À 2,1 mi, Ibis Lille Roubaix Centre Grand-place, Demi Lovato - Nightingale Traduction, Rmc Programme Radio, Plage Du Morlet, Logiciel Delphi 2019, Nombre De Jours D'école En 2020-2021, école Du Jeu Cours Du Soir, Magic Warriors Synopsis, Hotel Santa Maria3,3(56)À 1,2 km3 187 925 ₫, Kit Carrosserie Bmw F30, Randonnée Romanin Les Alpilles, Toilettage Chat Nice, Smic Annuel 2020, Le Métier De Journaliste Avantages Et Inconvénients, Fabricant Semelle Chaussure,

constant expression required java switch enum