# Cannot refer to the non-final local variable foo defined in an enclosing scope

**URL:** <https://forum.microej.com/t/cannot-refer-to-the-non-final-local-variable-foo-defined-in-an-enclosing-scope/1221>\
**Category:** Technical Support\
**Tags:** sdk\
**Created:** [January 23, 2023, 2:21pm UTC](https://forum.microej.com/t/cannot-refer-to-the-non-final-local-variable-foo-defined-in-an-enclosing-scope/1221 "2023-01-23T14:21:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![medhi.j](https://forum.microej.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@medhi.j](https://forum.microej.com/u/medhi.j)\
**Post date:** [January 23, 2023, 2:21pm UTC](https://forum.microej.com/t/cannot-refer-to-the-non-final-local-variable-foo-defined-in-an-enclosing-scope/1221/1 "2023-01-23T14:21:32Z")

</div>

Hi,

When I build my projects using the [dockerized SDK Tool](https://github.com/MicroEJ/Tool-SDK-Docker), I have the following errors:

```auto
Cannot refer to the non-final local variable foo defined in an enclosing scope

```

However, I don’t have such errors when I build directly from the SDK (4.1.5).

What is going on?

Best,

---

<div class="post-metadata">

**Author:** ![gjadi](https://forum.microej.com/user_avatar/forum.microej.com/gjadi/32/180_2.png) [@gjadi](https://forum.microej.com/u/gjadi)\
**Post date:** [January 23, 2023, 2:26pm UTC](https://forum.microej.com/t/cannot-refer-to-the-non-final-local-variable-foo-defined-in-an-enclosing-scope/1221/2 "2023-01-23T14:26:39Z")

</div>

Hi,

The difference of behavior is due to a non-conforming java compliance level in your SDK configuration.

The Java compliance level of MicroEJ Application is Java 1.7. ([official doc](https://docs.microej.com/en/latest/ApplicationDeveloperGuide/runtime.html#language))  
This is the default proposed by the templates in SDK 5.

To change the Java compliance level, go to `Window > Preferences > Java > Compiler` and select the compliance level 1.7 and rebuild the projects.

![forum-compliance-level](https://forum.microej.com/uploads/default/original/1X/9151cc286ebd3f752e51f8637afd177c60381755.png)

To fix the error itself, the variable must be final.  
For example:

```java
int foo = 0xdeadbeef;
Runnable r = new Runnable() {

	@Override
	public void run() {
		System.out.println(foo); // error because foo is non-final
	}
};

```

Instead, mark the variable as final:

```java
final int foo = 0xdeadbeef;
Runnable r = new Runnable() {

	@Override
	public void run() {
		System.out.println(foo); // OK because foo is final
	}
};

```

Best,
