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 <[email protected]> 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
>
>

Reply via email to