golang - different ways of initializing your struct /class




Different ways of initializing your struct

// Util.go

package main

type StringHelper struct {

}
func (sh StringHelper ) ToUpper() string{
   return "TOUPPER"}



Different ways of initializing :

// 1st 

var a StringHelper
a.ToUpper()

// 2nd

b := new(StringHelper)
b.ToUpper()

// 3rd

c := StringHelper{}
c.ToUpper()


I kinda prefer 3rd way of doing it.


Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm