On Fri, Jul 6, 2012 at 8:48 AM, Maksym Parkachov <lazy.gop...@gmail.com> wrote:
> I'm trying version 1.7 preview, which works great and fast btw.,  and
> becoming a lot of warning concerning singleton on non-persistent Java
> type.
>
> The pattern, I'm using:
>
> require 'java'
> java_import java.util.ArrayList
>
> class ArrayList
>   def psize
>     puts size
>   end
> end

This part is ok; reopening Java classes is fine.

> list = ArrayList.new
>
> list.instance_exec do
>   psize
>   add 10
>   psize
> end

This part does indeed cause a singleton to be created, under both MRI
and JRuby. That is unfortunately how instance_exec and instance_eval
work.

> I understand, that singleton class will be generated, if I change
> class definition with instance_exec, but executing methods should not
> create singleton ? Or should it ?

It does indeed. I had forgotten this myself, but as far as I can tell
the singleton is created right away just in case you *do* define
methods.

It may be possible to avoid creating the singleton, but I'm not sure
we'd be safe in doing so since MRI would stil do it.

> I would really appreciate suggestions on how to achieve above
> mentioned pattern, or maybe fix warning or generation of singleton.

At the moment, I know of no way to get exactly what you want, but I
will experiment a bit.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to