Overview of Go Generics

Let’s learn about Go generics and its features.

This lesson discusses Go generics, which is a forthcoming Go feature. As of the publication of this course, generics and Go are under discussion by the Go community. However, one way or another, it is good to know how generics work, its philosophy, and what the generics discussions are about.

Note: Go generics has been one of the most requested additions to the Go programming language.

The main idea behind generics in Go, as well as any other programming language that supports generics, is not having to write special code for supporting multiple data types when performing the same task.

Currently, Go supports multiple data types in functions, such as fmt.Println() using the empty interface and reflection.

However, demanding every programmer to write lots of code and implement lots of functions and methods for supporting multiple custom data types is not the optimal solution—generics come into play for providing an alternative to the use of interfaces and reflection for supporting multiple data types. The following code showcases how and where generics can be useful:

Get hands-on with 1200+ tech skills courses.