-
-
Save ohsitab/544243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// このようなクラスがあったとき | |
class T(prev: => T, next: => T) | |
// それぞれに変数を用意する場合は、このようにすれば循環参照を作成できるが | |
lazy val a: T = new T(c, b) | |
lazy val b: T = new T(a, c) | |
lazy val c: T = new T(b, a) | |
// このようなかんじに不定個の要素で循環参照を作成したい場合はどうすればよいだろうか | |
def f(n: Int) = (1 to n).foldLeft(null:T)((ref, _) => new T(ref, null)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment