zoukankan      html  css  js  c++  java
  • go 语言学习九

    package main
    
    import "fmt"
    
    func main() {
    /*
    	一个类型如果定义了指针接收者的String方法: func (p *Type) String() string {}
    	 打印这个类型的指针时会调用,
    	 打印这个类型的值时不会调用。
     */
    	var x Xint = 123
    	fmt.Println(x) // 123
    	fmt.Println(&x) // can not print Xint point.
    
    /*
    	一个类型如果定义了值接收者的String方法: func (p Type) String() string {}
    	打印这个类型的变量的值和指针都会调用
     */ 
    	
    	var y Yint = 123
    	fmt.Println(y) //can not print Yint.
    	fmt.Println(&y) //can not print Yint.
    	
    }
    
    type Xint int
    
    func (x *Xint) String() string {
    
    	return "can not print Xint point."
    }
    
    type Yint int
    
    func (x Yint) String() string {
    	
    	return "can not print Yint."
    }
    
  • 相关阅读:
    Java——GUI
    linux变量
    shell脚本
    linux查找文件命令
    composer的安装
    restful的nginx配置方法
    api调用安全
    PHP设置Cookie的HTTPONLY属性
    php的异常处理
    php错误报告
  • 原文地址:https://www.cnblogs.com/scala/p/9575221.html
Copyright © 2011-2022 走看看