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