Generics
Generics-in Əsas Məntiqi
Generics ilə Function Nümunəsi
package main
import "fmt"
func Compare[T comparable](a, b T) bool {
return a == b
}
func main() {
fmt.Println(Compare(10, 10)) // True, both are int
fmt.Println(Compare("Go", "Go")) // True, both are string
fmt.Println(Compare(3.14, 2.71)) // False, both are float64
}Bu Nümunədə:
Generics ilə Struct Nümunəsi
Bu Nümunədə:
Generics ilə Məhdudiyyətlər (Constraints)
Bu Nümunədə:
Nəticə
Last updated