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."
    }
    
  • 相关阅读:
    .NetMVC过滤器
    Vue-cli配置
    回顾2019年到今天
    八皇后问题
    约瑟夫环问题
    斐波那契函数列
    提高学习效率的方法
    感受爱阅读笔记
    Android IO流汇总
    Android的AsyncTask
  • 原文地址:https://www.cnblogs.com/scala/p/9575221.html
Copyright © 2011-2022 走看看