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


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. :slight_smile:

Minimal code would be:


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


class FinalTest2 extends FinalTest {}

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

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;

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.


Sounds like a bug, you should report it on Issues · HaxeFoundation/haxe · GitHub.