trifork / erjang

A JVM-based Erlang VM
http://www.erjang.org
Apache License 2.0
725 stars 62 forks source link

Unclear whether Erjang can interface with Java code, e.g. Android UI #63

Closed mcandre closed 11 years ago

mcandre commented 11 years ago

Can Erjang call Java code?

Can Erjang be used to write Android apps?

krestenkrab commented 11 years ago

Yes, Erjang can call Java code; syntax like:

foo() ->
    'java.lang.System':'gc'();

lets you call static Java methods. Returned objects can pose as Erlang terms. E.g. if it implements java.util.List, then it can pose as an Erlang list (i.e. you can match/deconstruct it). See more here: http://www.javalimit.com/2010/06/a-java-api-for-erjang.html

Currently, you cannot use Erjang to write Android apps; but it might not be totally undoable. Erjang has a byte code interpreter (use command line +i) which disables the to-JVM-bytecode-JIT, and this should in principle allow us to run apps on Android; but it has never been tried and there are probably a handful of classes that are being dynamically generated that could have been statically generated. Problem with Android is that dynamic code generation (JVM code) cannot be depended upon.