2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GoクイズAdvent Calendar 2020

Day 22

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?