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

ionic2 cordova build android - Unable resolve gradle 2.2.3

A quick tutorial for OWASP ZAP tool for beginners

OpenCover code coverage for .Net Core