go - Check for empty inline struct
问题描述
Can an inline struct in Go be checked for emptiness?
The following example checks p
, which is of type Person
for emptiness.
It also defines the inline struct i
. (How) can i
be checked for emptiness?
package main
import (
"fmt"
)
type Person struct {
name string
}
func main() {
// Types can be checked for emptiness.
p := Person{}
if (p == Person{}) {
fmt.Println("Empty!")
}
// But: how to check for an empty inline struct?
// I.e. how to check, if i is empty?
var i struct {
value int
}
fmt.Println(i) // Required, or compiler will complain about unused 'i'.
}
解决方案
推荐阅读
- sql - 如何在 SQL Server 中对来自 latin1 varchar 的字符进行编码以插入 MariaDB utf8?
- handlebars.js - 带有内联部分的车把加载器
- mysql - 警告:连接将被关闭,但有一个活动事务
- crypto++ - Crypto++ Ed448 未知 oid
- c# - Unity3D 网站查找在 Unity3D 4.7.2 中返回 nil
- java - 使用 Spring Security Adapter 时的 Keycloak 会话超时行为
- sql - 当我在 VB.NET 中修改 SQL 查询时,.tag 返回 Nothing
- angular - 返回函数的 Angular HTTP 请求
- c++ - 使用 Clang 和 MingW 将 C++ CMD 转换为简单的 Makefile
- c++ - CMAKE 中的 rpath 问题