groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From OC <...@ocs.cz>
Subject Hierarchy of singletons howto?
Date Fri, 01 Apr 2016 02:28:28 GMT
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