LoginSignup
2
1

More than 3 years have passed since last update.

Functional Optionのネスト

Last updated at Posted at 2020-12-18

初めてAdvent Calendarに投稿します!!
何かあればコメントいだだけるとありがたいですm(。。m)

次のコードを実行するとどうなるでしょうか?

package main

import (
    "fmt"
)

func main() {
    Step1("hello")
}

func Step1(v ...interface{}) {
    Step2(v, "world")
}

func Step2(v ...interface{}) {
    for _, obj := range v {
        for _, obj2 := range obj {
            fmt.Println(obj2)
        }
    }
}

A.
hello
world

B.
world
hello

C.
コンパイルエラー

D.
panic(実行時エラー)

正解はこちら
正解はCです。
Cannot range over 'obj' (type interface{}) でコンパイルエラーとなります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1