[erlang-questions] Use of Records in the Java API

Vlad Dumitrescu vladdu55@REDACTED
Sun Jun 22 21:59:37 CEST 2008


Hi,

On Wed, Jun 11, 2008 at 10:23 AM, Alexander Lamb
> <alexander.lamb@REDACTED> 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.

best regards,
Vlad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080622/5d9486bd/attachment.htm>


More information about the erlang-questions mailing list