[erlang-questions] Use of Records in the Java API
Sun Jun 22 21:59:37 CEST 2008
On Wed, Jun 11, 2008 at 10:23 AM, Alexander Lamb
> <> wrote:
> > My Erlang modules are mainly a server to Java Web applications (for
> > the time being).
> > This means that I am making a big use of the Erlang Java API which
> > works fine.
> > Since my Erlang modules use Mnesia to store data coming from the Java
> > side (and vice versa), I need to implement functions with many
> > parameters for example to insert new data in a Mnesia table.
> > I also need to convert tuples into actual Java objects when reading
> > data.
> > This would be simpler if the Java API had an OtpErlangRecord. It would
> > make it possible to subclass it and could even be the prefered way of
> > bridging the Erlang world with the Java world.
As Gleb pointed out, records are module local, and their name alone isn't
enough to tell them apart.
There is nothing that stops you to create your Java objects with a
constructor (or factory method) that takes an OtpErlangTuple as a parameter
and converts it to its Java counterpart. Conversely, a method similar to
toString, named for example toErlang, would make the opposite conversion.
Compared to an automatic conversion, this allows mappings that are more
complex that one-field-to-one-field.
The downside is that in most cases, this is boilerplate code.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions