无返回值

类 / 方法

new_counter <- function(count) {
  structure(list(count = count),
            class = "Counter")
}

report <- function(counter) {
  UseMethod("report")
}

# Called for its output only
report.Counter <- function(counter) {
  cat("count =", counter$count, "\n")
}

counter <- new_counter(11)
# No return: the call gives NULL
result <- report(counter)
# count = 11
no_value <- is.null(result)
# no_value = TRUE

cat("no_value =", no_value, "\n")