Recently, I have been working with Generic types in the Go language. In some cases, I need to use . I have already researched the Go documentation, but I couldn’t find any sample code for it.
Is it possible to achieve something similar to the code below in Go language?
class Person {
name: string
constructor(name: string) {
this.name = name
}
}
class Developer extends Person {
skill: string
constructor(name: string, skill: string) {
super(name)
this.skill = skill
}
}
function Greet<T extends Person>(a: T, b: T) {
console.log(a.name + " Hello " + b.name)
}
function main() {
const a = new Person('Person A');
const b = new Person('Person B');
const dev = new Developer('The dev', 'Fullstack')
Greet(a, b)
Greet(dev, a)
}
main()