6

perl6 中单例模式的正确实现是什么?

我已经尝试过了,但我不知道如何在 perl6 中使用 static 关键字:

4

1 回答 1

2

这是需要使用bless方法的少数原因之一

class Singleton {
    my Singleton $instance;
    method new {!!!}
    submethod instance {
        $instance = Singleton.bless unless $instance;
        $instance;
    }
 }
于 2018-04-03T07:31:37.010 回答