package main

import "fmt"

type Kotak[T any] struct {
	Isi T
}

// Method generik dengan type parameter sendiri.
func (k Kotak[T]) Ubah[U any](f func(T) U) Kotak[U] {
	return Kotak[U]{Isi: f(k.Isi)}
}

// UbahTeks menuntut method konkret, bukan method generik.
type UbahTeks interface {
	Ubah(f func(int) string) Kotak[string]
}

func main() {
	// Method generik tidak dapat mengimplementasikan method interface.
	var u UbahTeks = Kotak[int]{Isi: 21}
	fmt.Println(u.Ubah(func(n int) string { return fmt.Sprint(n) }).Isi)
}
