# Why does Type inference not work in the Processing editor?

**URL:** https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467
**Category:** Processing
**Created:** [April 19, 2019, 7:07pm UTC](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467 "2019-04-19T19:07:48Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 1, 2019, 4:32pm UTC](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467/21 "2019-05-01T16:32:16Z")

</div>

Now, if we simply use `final List<Double> list = new ArrayList<>();`  
Rather than `final List<? extends Double> list = new ArrayList<>();`  
Then `list.add(d);` works as it should: 🕶

```auto
import java.util.List;
import java.util.ArrayList;

public class Test {
  public final List<Double> list = new ArrayList<>();
  public final double d = Math.random();

  public Test() {
    list.add(d); // now it finally works!
  }

  @Override public String toString() {
    return list.toString();
  }

  @SafeVarargs public static final void main(final String... args) {
    System.out.println(new Test());
  }
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 1, 2019, 4:39pm UTC](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467/22 "2019-05-01T16:39:58Z")

</div>

Just found out that `final List<? super Double> list = new ArrayList<>();` works too! 🥳

Somehow only `final List<? extends Double> list = new ArrayList<>();` is problematic. 😕

---

<div class="post-metadata">

### Author: ![LoliProcessor](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LoliProcessor](https://discourse.processing.org/u/LoliProcessor)
#### Post date: [May 1, 2019, 6:23pm UTC](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467/23 "2019-05-01T18:23:50Z")

</div>

Oh yeah, I realized I confused these two right there.  
Of course, for super I can put Doubles in as I like.  
And on the other hand, for extends I can’t put in Doubles for sure but what you get is definitely a Double or inheriting from it.  
So  
List\<? extends Double\> L = new ArrayList\<\>();  
Double d = L.get(0);  
compiles, though would throw an error at runtime with this exact code only.

---

<div class="post-metadata">

### Author: ![LoliProcessor](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LoliProcessor](https://discourse.processing.org/u/LoliProcessor)
#### Post date: [May 2, 2019, 5:12pm UTC](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467/24 "2019-05-02T17:12:08Z")

</div>

I guess I’ll just add it here because it’s from the same corner, but lambda expressions don’t work either.  
Lambda expressions are allowed only at source level 1.8 or above  
☹

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 2, 2019, 9:41pm UTC](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467/25 "2019-05-02T21:41:25Z")

</div>

That’s right. I suspect a rule of thumb about the current syntax is “most of 7, bits of 8” – and unfortunately lambdas are not a part of 8 that got got. GoToLoop has been pining for adding lambdas to Processing for … maybe a decade…? Another rule of thumb is the more complex or abstract a Java feature is the less likely it is to have been prioritized for Antlr pre-processor handling. A few things were acquired essentially “for free” because the preprocessor didn’t have to be changed, just pass them through.

[Previous page](https://discourse.processing.org/t/why-does-type-inference-not-work-in-the-processing-editor/10467.md?page=1)
