Answers for "pointer to interface golang"

Go
0

golang interface pointer receiver

package main

import (
	"fmt"
)

type IFace interface {
	SetSomeField(newValue string)
	GetSomeField() string
}

type Implementation struct {
	someField string
}

func (i *Implementation) GetSomeField() string {
	return i.someField
}

func (i *Implementation) SetSomeField(newValue string) {
	i.someField = newValue
}

func Create() *Implementation {
	return &Implementation{someField: "Hello"}
}

func main() {
	var a IFace
	a = Create()
	a.SetSomeField("World")
	fmt.Println(a.GetSomeField())
}
Posted by: Guest on June-02-2021
0

Pointers in golang

func main () {
  b := *getPointer()
  fmt.Println("Value is", b)
}
Posted by: Guest on December-29-2021

Browse Popular Code Answers by Language