new_counter <- function(count) {
structure(list(count = count),
class = "Counter")
}
report <- function(counter) {
UseMethod("report")
}
# 调用只是为了它的输出
report.Counter <- function(counter) {
cat("count =", counter$count, "\n")
}
counter <- new_counter(11)
# 没有返回值:调用得到 NULL
result <- report(counter)
# count = 11
no_value <- is.null(result)
# no_value = TRUE
cat("no_value =", no_value, "\n")