// Sample program to show how to declare methods and how the Go
// compiler supports them.
package main import (
"fmt"
) // user defines a user in the program.
type user struct {
name string
email string
} // notify implements a method with a value receiver.
func (u user) notify() {
fmt.Printf("Sending User Email To %s<%s>\n",
u.name,
u.email)
} // changeEmail implements a method with a pointer receiver.
func (u *user) changeEmail(email string) {
fmt.Printf("change Email from <%s> To <%s>\n", u.email, email)
u.email = email
} // main is the entry point for the application.
func main() {
// Values of type user can be used to call methods
// declared with a value receiver.
bill := user{"Bill", "bill@email.com"}
bill.notify() // Pointers of type user can also be used to call methods
// declared with a value receiver.
lisa := &user{"Lisa", "lisa@email.com"}
lisa.notify()
fmt.Println()
// Values of type user can be used to call methods
// declared with a pointer receiver.
bill.changeEmail("bill@newdomain.com")
bill.notify() // Pointers of type user can be used to call methods
// declared with a pointer receiver.
lisa.changeEmail("lisa@newdomain.com")
lisa.notify()
}

输出

Sending User Email To Bill<bill@email.com>
Sending User Email To Lisa<lisa@email.com> change Email from <bill@email.com> To <bill@newdomain.com>
Sending User Email To Bill<bill@newdomain.com>
change Email from <lisa@email.com> To <lisa@newdomain.com>
Sending User Email To Lisa<lisa@newdomain.com>

go 接口以及对象的使用的更多相关文章

  1. Swift是一个提供RESTful HTTP接口的对象存储系统

    Swift是一个提供RESTful HTTP接口的对象存储系统,最初起源于Rackspace的Cloud Files,目的是为了提供一个和AWS S3竞争的服务. Swift于2010年开源,是Ope ...

  2. 探讨 java中 接口和对象的关系

    接口是对象么?接口可以有对象么?这个问题要跟类比对着,或许更好理解;类是对象的模版.接口不是类,所以:接口肯定不是对象的模版.那接口跟对象有什么样的关系?还是得从类入手;因为类实现了接口,所以可以说, ...

  3. Feign get接口传输对象引发一场追寻

    一个报错引发的追寻之路: Feign get接口传输对象,调用方接口代码: @FeignClient(name = "manage") public interface Acces ...

  4. Effective Java 第三版——64. 通过对象的接口引用对象

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  5. 实现现下列哪一种接口的对象,并不需要在web.xml文件内进行额外的设定,Servlet容器就能够回应该对象加入HTTP会话所发生的事件?(选择1项)

    实现现下列哪一种接口的对象,并不需要在web.xml文件内进行额外的设定,Servlet容器就能够回应该对象加入HTTP会话所发生的事件?(选择1项) A.ServletContextListener ...

  6. Swift是一个提供RESTful HTTP接口的对象存储系统,目的是为了提供一个和AWS S3竞争的服务

    Swift是一个提供RESTful HTTP接口的对象存储系统,最初起源于Rackspace的Cloud Files,目的是为了提供一个和AWS S3竞争的服务. Swift于2010年开源,是Ope ...

  7. Delphi 与 VC 共享接口和对象

    我经常会用 Delphi 写一些工具和应用,为了扩展方便,大部分都会做成插件形式. 迫于某些原因,我的插件不得不用其他开发工具来完成,比如 VC. 于是有个大问题需要解决:如何让 D 和 VC 互相通 ...

  8. AOP之proceedingjoinpoint和joinpoint区别(获取各对象备忘)、动态代理机制及获取原理代理对象、获取Mybatis Mapper接口原始对象

    现在AOP的场景越来越多,所以我们有必要理解下和AOP相关的一些概念和机制. import org.aspectj.lang.reflect.SourceLocation; public interf ...

  9. Java泛型:泛型的定义(类、接口、对象)、使用、继承

    地址   http://blog.csdn.net/lirx_tech/article/details/51570138 1. 设计泛型的初衷: 1) 主要是为了解决Java容器无法记忆元素类型的问题 ...

  10. FCL研究-集合- System.Collections 接口和对象集合

    [目录] 发现自己已经有很长一段时间写代码没什么进步了,随便读读FCL的源码,看看之前一直用的方法是如何实现的,也顺便提高下自己.FCL很是庞大,很难下口,于是用最笨的办法,先看常见的命名空间,逐个展 ...

随机推荐

  1. 利用Python实现多线程聊天功能

    #-*- coding:utf-8 -*- from threading import Thread from socket import * #1.实现接收消息 def recvDate(): wh ...

  2. django ORM聚合函数

    在Django中,聚合函数是通过aggregate方法实现的,aggregate方法返回的结果是一个字典 在使用时需要先导入模块from django.db.models import Count,A ...

  3. SVN更新无数次后仍显示Out of date

    理器相集成的TortoiseSVN更是方便. 但有时候在提交修改后的文件时,却莫名其妙的出现out of date错误,导致工程无法commit,即使将新文件删了重新update,然后再在旧文件上作修 ...

  4. Cannot resolve reference to bean 'sqlSessionFactory' while setting bean

    今天下载公司以前的一个项目,要和现在的项目进行整合,下载一切顺利,但在开发机器上一跑,憋了. 有两种日志,两种报错:一个是cannot resolve reference to bean 'sqlSe ...

  5. MySql数据库概念

    一.什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的建立在计算机存储设备上的仓库. 简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进行 ...

  6. 4、pandas的数据筛选之isin和str.contains函数

    DataFrame列表: 以>,<,==,>=,<=来进行选择(“等于”一定是用‘==’,如果用‘=’就不是判断大小了): 使用 &(且) 和 |(或) 时每个条件都要 ...

  7. yolo3(目标检测)实测

    yolo是继faster-r-cnn后,原作者在目标检测领域进行的新研究.到了v3版本以后,虽然已经换人支持,但是更注重工程实践,在实际使用过程中突出感受就是 “非常快”,GPU加速以后能够达到实时多 ...

  8. shelve模块,sys模块,logging模块

    1.shelve模块 用于序列化的模块,shelve模块比pickle模块简单,只有open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型. impor ...

  9. MFC限制edit控件的字符输入长度

    一. 1.Edit 控件添加EN_CHANGE事件 #define MAX_SIZE 200 void CMyDlg::OnChangeEditFeed() { // TODO: 如果该控件是 RIC ...

  10. 本地git远程github

    操作环境: windows系统 本地已安装git 步骤 1.右键进入git bash 2.进入本地仓库,如果有,则跳到步骤3.如果没有,则找到要作为仓库的文件夹,例如e://git//reposito ...