假设我在R中有一个Reference类定义,它的字段本身就是引用类:
A <- setRefClass("A", fields = list(aVar = "numeric"))
B <- setRefClass("B", fields = list(bVarOne = "numeric", bVarTwo = "ANY"))
myBinst <- B$new(bVarOne = 10, bVarTwo = A$new(aVar = 5))
str(myBinst)
Reference class 'B' [package ".GlobalEnv"] with 2 fields
$ bVarOne: num 10
$ bVarTwo:Reference class 'A' [package ".GlobalEnv"] with 1 field
..$ aVar: num 5
..and 12 methods.
and 12 methods.
引用类实例可以用.self引用它们,它们是否可以引用包含它们作为字段的引用类的实例,即在本例中,包含在B实例中的A实例是否可以引用B?如果是这样,我该怎么做?
谢谢, 本。