# Switch expressions not working in Processing 4

**URL:** https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486
**Category:** Processing
**Created:** [February 28, 2022, 11:40pm UTC](https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486 "2022-02-28T23:40:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Saaan](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@Saaan](https://discourse.processing.org/u/Saaan)
#### Post date: [February 28, 2022, 11:40pm UTC](https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486/1 "2022-02-28T23:40:56Z")

</div>

I’m using Processing 4 which is on Java 17.0.2, but for some reason it won’t allow switch expressions? This compiles in other IDEs so I’m not sure what’s going on here, does anyone know the reason for this, if it is fixable, or if it should be submitted as an issue?

```java
void setup() {
  int a = 0;
  int b = switch(a) {
    case 0 -> 0;
    default -> 1;
  };
  exit();
}

```

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [March 1, 2022, 4:26am UTC](https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486/2 "2022-03-01T04:26:27Z")

</div>

Your switch expression isn’t using proper syntax.

See here: [Reference / Processing.org](https://processing.org/reference/switch.html)

Try instead:

```auto
void setup() {
  int a = 0;
  switch(a) {
    case 0:
      print("0 case");
      break;
    default:
      println("default");
      break;
  }
  exit();
}

```

---

<div class="post-metadata">

### Author: ![Saaan](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@Saaan](https://discourse.processing.org/u/Saaan)
#### Post date: [March 1, 2022, 6:27am UTC](https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486/3 "2022-03-01T06:27:18Z")

</div>

That’s a switch statement, I’m referring to switch expressions, a feature release in Java 14 (preview since Java 12): [Switch Expressions](https://docs.oracle.com/en/java/javase/13/language/switch-expressions.html)

The syntax is definitely right because I can compile that switch expression in other compilers that are also on newer Java versions. It works in an online IDE on Java 17.0.1, and Processing 4 is on 17.0.2.

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [March 1, 2022, 8:53am UTC](https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486/4 "2022-03-01T08:53:48Z")

</div>

Ah. My mistake. It’s possible that Processing is unaware of - or simply doesn’t support - that syntax for switch expressions. While Processing code is very Java-like, it is not _actually_ Java; instead, it is very tricky and _compiles down_ to Java. This compiling process (sic) hides lots of implementation details (like, for example, making setup() and draw() run once and continuously).

You’ll have to change your Processing code to use Processing syntax, or you can switch to Java!

---

<div class="post-metadata">

### Author: ![Mattyjak](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mattyjak/32/16777_2.png) [@Mattyjak](https://discourse.processing.org/u/Mattyjak)
#### Post date: [March 3, 2022, 12:22am UTC](https://discourse.processing.org/t/switch-expressions-not-working-in-processing-4/35486/5 "2022-03-03T00:22:38Z")

</div>

Yeah, Processing uses a really outdated version of Java. It doesn’t support lambda syntax so you’ve gotta find a workaround. Try using the older syntax as a fix.
