Go course

GenericsQuiz: Generics

Go

Display

Theme

Generics · Quiz

Quiz: Generics

Test what you know about type parameters, constraints, and generic types. Answer every question in the panel on the right.

  1. Question 1 of 5Why does this code fail to compile?
    func Sama[T any](a, b T) bool {
    	return a == b
    }
  2. Question 2 of 5Given type Meter float64. Which constraint accepts Meter?
  3. Question 3 of 5What is T when calling this function?
    func Pertama[T any](s []T) T { return s[0] }
    
    x := Pertama([]string{"apel", "jeruk"})
  4. Question 4 of 5What's the correct way to get the zero value of a type parameter T inside a generic function?
  5. Question 5 of 5Which situation LEAST needs generics?