golang中的可选类型,如打字稿
问题描述:
In typescript, you can have an optional type like :
interface SquareConfig {
color?: string;
width?: number;
}
Is this allowed in Golang? How do I achieve that?
在打字稿中,您可以有一个可选类型,例如: p>
接口SquareConfig {
颜色?:字符串;
宽度?:数字;
}
code> pre>
在Golang中允许吗? 我该如何实现? p>
div>
答
Is this allowed in Golang?
No.
Btw: The language is called "Go".
How do I achieve that?
You do some programming, like using pointers or adding a bool which indicates validity of the fields.