groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alessio Stalla <alessiosta...@gmail.com>
Subject Re: Hierarchy of singletons howto?
Date Fri, 01 Apr 2016 09:48:25 GMT
Your requirement is logically inconsistent. If there is only one possible
instance of Foo, there cannot be /another/ instance of Foo which is also a
Bar.

On 1 April 2016 at 04:28, OC <ocs@ocs.cz> wrote:

> Hello there,
>
> how do you make a hierarchy of classes, each of which happens to be a
> singleton?
>
> The naïve solution simply does not work:
>
> ===
> 85 /tmp> <qq.groovy
> @Singleton class Foo { }
> @Singleton class Bar extends Foo { }
>
> println "Foo: ${Foo.instance}, Bar: ${Bar.instance}"
> 86 /tmp> groovy qq
> Caught: java.lang.IllegalAccessError: tried to access method Foo.<init>()V
> from class Bar
> java.lang.IllegalAccessError: tried to access method Foo.<init>()V from
> class Bar
>         at Bar.<init>(qq.groovy)
>         at Bar.<clinit>(qq.groovy)
>         at qq.run(qq.groovy:4)
> 87 /tmp>
> ===
>
> What is the proper way to achieve this?
>
> Thanks a lot,
> OC
>
>

Mime
View raw message