About 277,000 results
Open links in new tab
  1. Go with Generics: type *T is pointer to type parameter, not type ...

    Mar 11, 2022 · About using *T In short, a type parameter is not its constraint. The constraint only determines what operations are available on T, it doesn't imply anything about *T, which is …

  2. How can I write a generic function that accepts any numerical type?

    Coming from JavaScript and TypeScript, I wanted to check out Go and make a simple calculator. Since there's the difference between int and float, what is the preferred way to write a function …

  3. How to create generic method in Go? (method must have no type ...

    Jan 11, 2022 · Methods are not permitted to have type params not specified on the type of the receiver. The reason is that interfaces in Go are implemented implicitly, so it is yet unclear how …

  4. go - Return default value for generic type - Stack Overflow

    Jan 5, 2022 · The *new(T) idiom This has been suggested as the preferred option in golang-nuts. It is probably less readable but easier to find and replace if/when some zero-value builtin gets …

  5. go - How to implement generic interfaces? - Stack Overflow

    Apr 27, 2022 · Types don't actually implement generic interfaces, they implement instantiations of generic interfaces. You can't use a generic type (including interfaces) without instantiation. …

  6. Generic Structs with Go - Stack Overflow

    Jun 28, 2021 · What is the equivalent of this C# code in Go, how can I build it class ModelX<T> { public T Data { get; set; } } ModelX<int> I have tried something like: t...

  7. Go generics: is it possible to embed generic structs?

    Feb 9, 2021 · The current generics proposal does say that this should be possible: When a generic type is a struct, and the type parameter is embedded as a field in the struct, the name …

  8. Why are there no generics in Go? - Stack Overflow

    Generics may well be added at some point. We don't feel an urgency for them, although we understand some programmers do. Generics are convenient but they come at a cost in …

  9. In Go, how can I make a generic function with slices?

    Jul 22, 2016 · Seeing as all of the answers here were written before go added generics, I'll add how you would implement this in go1.18+ Note, however, that as of go1.21, there is a slices …

  10. In Go generics, why can't I use comparable constraint with order ...

    Jan 3, 2022 · I am exploring go generics (1.18 beta), and have questions related to comparing two numerical values (a simple method that takes two values and returns a greater number). …