不要以这种方式使用延迟初始化。没有卡片的 Deck 是无用的,因此,每当第一次调用该 getter 时,延迟初始化只会给您带来不确定的 CPU 消耗。幸运的是,简单地创建一个可变数组没有任何成本(这也是不使用延迟初始化的原因)。
As well, vending a mutable collection breaks encapsulation. A Deck should contain all the logic for determine what set of Cards it contains and in what order. By vending a mutable collection, an external bit of code can change that order behind the Deck's back.
Beyond that, what does it even mean to "set" a Deck's cards? Going that route seemingly pushes all logic related to maintaining the Deck outside of the Deck class, begging the question as to why the deck is nothing more than a plain old array in whatever class uses the deck.