diff --git a/lesson8/05_generic_print.go b/lesson8/05_generic_print.go new file mode 100644 index 0000000..67af4f5 --- /dev/null +++ b/lesson8/05_generic_print.go @@ -0,0 +1,23 @@ +// Type parameters introduced to Go in version 1.18 +// -> generic function! + +// Now the function printValue accepts value of any type + +// (in Scala - any is "top type", none is "bottom type") + +package main + +import "fmt" + +func printValue[T any](value T) { + fmt.Println(value) +} + +func main() { + printValue("www.root.cz") + printValue('*') + printValue(42) + printValue(3.14) + printValue(1 + 2i) + printValue([]int{1, 2, 3}) +}