# Problems with generated Java code when having final fields in Base-Class

**URL:** <https://community.haxe.org/t/problems-with-generated-java-code-when-having-final-fields-in-base-class/925>\
**Category:** Haxe\
**Tags:** haxe-java\
**Created:** [August 1, 2018, 1:15pm UTC](https://community.haxe.org/t/problems-with-generated-java-code-when-having-final-fields-in-base-class/925 "2018-08-01T13:15:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bergm](https://community.haxe.org/user_avatar/community.haxe.org/bergm/32/246_2.png) [@bergm](https://community.haxe.org/u/bergm)\
**Post date:** [August 1, 2018, 1:15pm UTC](https://community.haxe.org/t/problems-with-generated-java-code-when-having-final-fields-in-base-class/925/1 "2018-08-01T13:15:36Z")

</div>

Hi,

I’m trying to inherit from a Java class, which has protected final member variables. In the generated Java code the compiler creates for instance the \_\_hx\_setField\_f method where setting the final field is attempted, so the Java compilation fails.  
Is there any way to prevent this? Is it just a bug?  
Ideas are highly appreciated. 🙂

Minimal code would be:

(Java)

```haxe
package test;
public class FinalTest {
    protected final int protFinalField = 0;
}

```

(Haxe)

```haxe
class FinalTest2 extends FinalTest {}

```

Then in the generated file for FinalTest2.java, code like the following will be found:

```haxe
 .....
public double __hx_setField_f(java.lang.String field, double value, boolean handleProperties)
{
	{
		boolean __temp_executeDef1 = true;
		switch (field.hashCode())
		{
			case -612101141:
			{
				if (field.equals("protFinalField")) 
				{
					__temp_executeDef1 = false;
					this.protFinalField = ((int) (value) );
					return value;
				}
					
				break;
			}
		}
.....

```

I hope that helps. Maybe there is even a switch to prevent the creation of that code, if not needed and I just didn’t find it.

Thank you.

Michael

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [August 19, 2018, 3:38pm UTC](https://community.haxe.org/t/problems-with-generated-java-code-when-having-final-fields-in-base-class/925/2 "2018-08-19T15:38:57Z")

</div>

Sounds like a bug, you should report it on [Issues · HaxeFoundation/haxe · GitHub](https://github.com/haxefoundation/haxe/issues).
