当前位置:网站首页>Go learning --- use reflection to judge whether the value is valid
Go learning --- use reflection to judge whether the value is valid
2022-07-06 07:11:00 【Duck boss】
One 、 Use reflection to determine whether the value is valid
package main
import (
"fmt"
"reflect"
)
// Define a structure
type Tom struct {
}
func main() {
var a *int
isNilA := reflect.ValueOf(a).IsNil()
fmt.Println(" Determine whether the pointer is initialized :",isNilA)
var b *int = new(int)
isNilB := reflect.ValueOf(b).IsNil()
fmt.Println(" Determine whether the pointer is initialized :",isNilB)
var c int
zero := reflect.ValueOf(c).IsZero()
fmt.Println("c Whether the value of is zero :",zero)
c = 1
zeros := reflect.ValueOf(c).IsZero()
fmt.Println("c Whether the value of is zero :",zeros)
var d int
// To see if it works
valid := reflect.ValueOf(d).IsValid()
fmt.Println("d Whether it works :",valid)
d = 2
fmt.Println("d Whether it works :",reflect.ValueOf(d).IsValid())
tom := Tom{}
fmt.Println(" Whether the internal attribute name of the structure is valid ",reflect.ValueOf(tom).FieldByName("name").IsValid())
fmt.Println(" Whether the structure method is effective :",reflect.ValueOf(tom).MethodByName("name").IsValid())
m := make(map[interface{}]interface{})
fmt.Println(reflect.ValueOf(m).MapIndex(reflect.ValueOf(3)).IsValid())
}
边栏推荐
- RichView TRVStyle 模板样式的设置与使用
- The difference between get and post request types
- 【Hot100】739. Daily temperature
- Leetcode 78: subset
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Project GFS data download
- Compile, connect -- notes-2
- [hot100] 739. Température quotidienne
- leetcode6109. 知道秘密的人数(中等,周赛)
- 将ue4程序嵌入qt界面显示
猜你喜欢

Internal and external troubles of "boring ape" bayc

SSM学习

Markdown 中设置图片图注

C language_ Double create, pre insert, post insert, traverse, delete

UWA pipeline version 2.2.1 update instructions

Proteus -- Serial Communication parity flag mode

Entity Developer数据库应用程序的开发

Cif10 actual combat (resnet18)

Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution

Raspberry pie serial port login and SSH login methods
随机推荐
Cookie Technology & session Technology & ServletContext object
Multithreading and concurrent programming (2)
The differences and advantages and disadvantages between cookies, seeion and token
PCL realizes frame selection and clipping point cloud
Crawling exercise: Notice of crawling Henan Agricultural University
idea控制台彩色日志
Interface automation test framework: pytest+allure+excel
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
1091: two or three things in childhood (multi instance test)
SSM learning
“无聊猿” BAYC 的内忧与外患
Project GFS data download
Misc of BUU (update from time to time)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
(4) Web security | penetration testing | network security web site source code and related analysis
leetcode841. 钥匙和房间(中等)
变量的命名规则十二条
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor