首页 > 其他分享 >golang_class

golang_class

时间:2022-10-15 17:35:51浏览次数:39  
标签:name age fmt alice golang Person func class

func (this Person) 和 func (this *Person)的区别

func (this Person)

package main

import (
	"fmt"
)

type Person struct {
	name string
	age  int
}

func (this Person) show() {
	fmt.Println("name=", this.name, "age=", this.age)
}

func (this Person) setName(name string) {
	this.name = name
}

func main() {
	alice := Person{"Alice", 19}
	alice.show()
	fmt.Println("------------")
	alice.setName("alice111")
	alice.show()
}

VVV

name= Alice age= 19
------------
name= alice111 age= 19

func (this *Person)

package main

import (
	"fmt"
)

type Person struct {
	name string
	age  int
}

func (this *Person) show() {
	fmt.Println("name=", this.name, "age=", this.age)
}

func (this *Person) setName(name string) {
	this.name = name
}

func main() {
	alice := Person{"Alice", 19}
	alice.show()
	fmt.Println("------------")
	alice.setName("alice111")
	alice.show()
}

VVV

name= Alice age= 19
------------
name= alice111 age= 19

标签:name,age,fmt,alice,golang,Person,func,class
From: https://www.cnblogs.com/zhuoss/p/16794591.html

相关文章

  • jmeter执行报错:java.lang.UnsupportedClassVersionError解决办法
    做个记录。问题记录:jmeter版本:5.4.1本地Java版本:1.8.0_151执行jmeter,报错:  2022-10-1412:06:27,372ERRORo.a.j.JMeter:Uncaughtexceptionint......
  • SVN报错Skipped ‘xxxController.class.php‘ -- Node remains in conflict
    节点冲突,接下来我们更新一下节点就好。把当前节点更新为初始节点svnrevert--depth=infinityxxxController.class.php这里的xxxController.class.php就是冲突的那个文件......
  • 第二章 Golang的概述
    2.1什么是程序whyisGo语言?Go语言是区块链最主流的编程语言,同时也是当前最具发展潜力的语言。Go语言是Google公司创造的语言,也是Google主推的语言。国外如Google、AWS、......
  • Python在Class中实现装饰器
    函数装饰器普通的装饰器较为简单,关键点只有两个,一个是闭包的概念,一个是函数作为参数进行传递,让我们先实现一个简单的装饰器。defhuat(f):deffunc():prin......
  • PHPExcel PHP Class 'ZipArchive' not found
    PhpSpreadsheet是PHPExcel的下一个版本。它打破了兼容性,极大地提高了代码库的质量(命名空间,PSR合规性,使用最新的PHP语言功能等)。由于所有努力都转移到了PhpSpreadsheet,PHP......
  • python中@classmethod和@staticmethod方法
    在python类当中,经常会遇到@classmethod和@staticmethod这两个装饰器,那么到底它们的区别和作用是啥子呢?具体来看下。@classmethod:默认有一个cls参数,用类或对象都可以调用......
  • [Typescript] Abstract Classes
    Youcannotcreateainstanceofabstractclass.Anabstractclassmeantobeextended.abstractclassSize{constructor(publicsizes:string[]){}......
  • 关于python class
    1、class的定义classX(Y)"MakeaclassnamedXthatis-aY."classX(object):def__init__(self,J)"classXhas-a__init__thattakesselfandJpar......
  • Redis延迟队列golang高效实践
    一、背景 业务中经常会有这样的场景: 到期后自动执行指定操作; 查询某个任务是否完成,未完成等待一定时间再次查询; 回调通知,当回调失败时,等待后重试;等等还......
  • [Typescript] Get class properties type in union
    Forexamplethereisaclas:exportclassModifierState{/***Returnsthemodifierstateapplicabletothekeyboardeventgiven.*......