Some news about haXe/Java
Hello,
Sometimes ago I’ve been talking about haXe/Java and show-casing it with a very simple Android Application sample.
Obviously, the generated buzz has been quite huge (compared to our community’s size) but I’ve been surprised that no one contacted me to participate in the project.
Some days after, some events happened that prevented me to continue most of my personal work (you know, those kind of things that makes you wonder if you were right at the first place).
Well, that was before.
About a month ago, I’ve been contacted by several persons, some representing companies, some individuals. Some are offering sponsorship and some are offering help.
This is a great thing and I’m now quite excited about continuing the work on haXe/Java since I see people are really interested in it.
So, I’m going to write about some “problems” I have to face while writing this Java target.
haXe Void against Java Void
As you certainly know, haXe has a type Void. When you’re using it, it means that your function may return nothing (using a simple “return;” for example) or return null.
Java can also declare methods as void, but in such a case they can only “return;”. Although this may seem to be a very small difference it’s a quite important one.
The first idea would be to create a type “haXe.Void” to be used when we generate the Java code : that would actually allow us to return null.
But it has a drawback : Java makes an extensive use of method overriding (you can see that in the Android API for example), and a method declared as void in Java wouldn’t be overridable from haXe.
The second possibility would be to type as “void” and transform “return null;” to a simple “return;”. This is a possibility but I’m actually not feeling very comfortable with it because I feel like it may change the behavior of something at some time… (maybe throwing some problems when doing a == null).
Third possibility : let the developer choose the behavior to use by compiling Void to haXe.Void and having a java.Void that compiles to java’s native void.
What do you think about it ?