When to Use Generics in Go?


./main.go:29:15: methods cannot have type parameters

Common uses and misuses

In this case, using generics wouldn’t bring any value whatsoever, and we should make the w argument an io.Writer directly:





Software Engineer, Go, Rust, Java | 改善

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

6 Steps to add Computer Vision Super Powers to your Kotlin Android App

Switching To A Window Manager

☁Rethinking server lifecycle management: A bold new approach⚡

How to Serve an Image From an S3 Bucket Using CloudFront

Getting more from your Laptop with the help of Undervolting

How to evolve your network to be ad-free with Pi-Hole®

Using localstack to replace AWS services for local development

5 tools to help you disrupt your sprint retrospectives

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Teiva Harsanyi

Teiva Harsanyi

Software Engineer, Go, Rust, Java | 改善

More from Medium

Golang: How To Implement Concurrency With Goroutines and Channels

Reinvent the Wheel Ep. 1: Removing Unused Files

Injecting Interfaces — Golang Dependency Injection

Battle of Concurrency | Goroutines vs Threads.