Go言語 ジェネリクス

package main

import "fmt"

// func showIntThreeTimes(num int) {
//     fmt.Println(num)
//     fmt.Println(num)
//     fmt.Println(num)
// }

// func showFloat64ThreeTimes(num float64) {
//     fmt.Println(num)
//     fmt.Println(num)
//     fmt.Println(num)
// }

func showThreeTimes[T any](num T) {
    fmt.Println(num)
    fmt.Println(num)
    fmt.Println(num)
}

func main() {
    // showIntThreeTimes(3)
    // showFloat64ThreeTimes(5.2)
    showThreeTimes(3)
    showThreeTimes(5.2)
}

投稿者: chosuke

趣味はゲームやアニメや漫画などです

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です