switch-statement

java 8: difference between class.getName() and String literal [duplicate]

六眼飞鱼酱① 提交于 2020-06-22 18:50:15
问题 This question already has answers here : Java switch statement: Constant expression required, but it IS constant (13 answers) Closed 4 years ago . I was working on switch case. If we use class.getName(), then, I am getting error that "case expressions must be constant expressions" as follows: switch(param.getClass().getName()) { case String.class.getName(): // to do break; } Even if we do following, take string class name in a constant, then also, getting same error: public static final

Using a switch statement with a for loop change data retrieved

旧街凉风 提交于 2020-06-17 15:49:55
问题 I am using processing with a file that has data in different columns. I am wanting to change the data being pulled for each column with each switch. I have a value toggle set as my variable so the value changes when clicked. 0-2. Currently I am able to run toggle, but the values do not change. Below is the current switch statement I have. For full code and associated files see Link PImage mapImage; Table locationTable; int rowCount; Table dataTable; float dataMin = MAX_FLOAT; float dataMax =

Force DAX SWITCH function to use strict (lazy) short-circuit evaluation

风流意气都作罢 提交于 2020-06-15 07:21:52
问题 Set up: Similar to this question on a MSDN forum, I have a measure that switches between various other measures (some of them much more complex than others). The measure looks like this (my actual measure has more cases): VariableMeasure = VAR ReturnType = SELECTEDVALUE ( ParamReturnType[ReturnType] ) SWITCH ( ReturnType, "NAV", [Nav], "Income", [Income], "ROI", [Roi], "BM", [Benchmark], BLANK () ) Context: The reason for the switching measure is to have the ability to choose which measures

reduce the number of non-empty switch cases sonar lint issue

谁说胖子不能爱 提交于 2020-06-01 06:26:08
问题 I have around 100 non-empty cases inside a switch case. Each case calls different functions. Sonar is showing issue to reduce number of non-empty switch cases to atmost 30. Is there any alternative to implement such switch cases or there is no problem in having any number of switch cases. for(int i=0;i<arrayList.size();i++){ switch(arrayList.get(i)){ case "A": a(); break; case "B": b(10,20); break; ... ... case "ABZ": abz("string1","string2"); break; } } 来源: https://stackoverflow.com

Switch: Multiple values in one case?

百般思念 提交于 2020-05-25 08:57:21
问题 I have the following piece of code, but yet when I enter "12" I still get "You an old person". Isn't 9 - 15 the numbers 9 UNTIL 15? How else do I handle multiple values with one case? int age = Convert.ToInt32(txtBoxAge.Text); switch (age) { case 1 - 8: MessageBox.Show("You are only " + age + " years old\n You must be kidding right.\nPlease fill in your *real* age."); break; case 9 - 15: MessageBox.Show("You are only " + age + " years old\n That's too young!"); break; case 16-100: MessageBox

Why is this switch case not working in Netbeans?

萝らか妹 提交于 2020-05-17 06:57:06
问题 Switch case is taking value but only the default case is running. int z = Integer.parseInt(x); JOptionPane.showMessageDialog(null,+z); switch (z) { case ('1'): C.SetEmpInformation(); break; case ('2'): C.UpdateEmpInformation(); break; default: JOptionPane.showMessageDialog(null, "Invalid Identity"); } 回答1: Remove the single quotes in your case statements. They will be matched as char and not as int . '1' is a character and very different from the number 1. switch (z) { case 1: /* .... */ case

Why is this switch case not working in Netbeans?

你离开我真会死。 提交于 2020-05-17 06:55:34
问题 Switch case is taking value but only the default case is running. int z = Integer.parseInt(x); JOptionPane.showMessageDialog(null,+z); switch (z) { case ('1'): C.SetEmpInformation(); break; case ('2'): C.UpdateEmpInformation(); break; default: JOptionPane.showMessageDialog(null, "Invalid Identity"); } 回答1: Remove the single quotes in your case statements. They will be matched as char and not as int . '1' is a character and very different from the number 1. switch (z) { case 1: /* .... */ case

Why Does My Prefix Expression Evaluator Program Miscalculate Any Addition or Subtraction?

吃可爱长大的小学妹 提交于 2020-05-17 05:56:28
问题 I have a program that is meant to take in a Queue<String> that contains the elements of a prefix operation (i.e. an operation that is stated "+ 4 2" instead of "4 + 2", which is infix), then output the integer answer (just assume that a double is never needed, okay?). It works correctly for any multiplication or division operation, but fails in any addition or subtraction operation, and worse, in an inconsistent manner. For example, the output to "- 5 1" is 5, which would suggest it's adding

Powershell “special” switch parameter

别说谁变了你拦得住时间么 提交于 2020-04-28 09:58:31
问题 I have the powershell function below Function Test { Param ( [Parameter()] [string]$Text = "default text" ) Write-Host "Text : $($Text)" } And I would like to be able to call this function like below : Test -Text : should display the default text on the host Test -Text "another text" : should display the provided text on the host My issue is that the first syntax is not allowed in powershell .. Any ideas of how I can achieve this goal ? I would like a kind of 'switch' parameter that can take

What does this syntax of switch case mean?

余生长醉 提交于 2020-04-05 05:44:46
问题 I saw some C code like this: int check = 10: switch(check) { case 1...9: printf("It is 2 to 9");break; case 10: printf("It is 10");break; } What does this case 1...9: mean? Is it standard? 回答1: It's a GNU C extension called case range . http://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html As noted in the document, you have to put spaces between the low and high value of the range. case 1 ... 9: statement; is equivalent to: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: