3 ms·
Well, yes kind of. type foo struct { a int // "private" B int // "public" } You cannot specify default values and Go refers to them as
by barsonme 10y ago
Well, yes kind of.
type foo struct {
a int // "private"
B int // "public"
}
You cannot specify default values and Go refers to them as "exported" not private, but technically they are "private" in the sense that they can only be accessed via methods.
- kuschku 10y agois a field named "ß" private or public? Or ĸ?
- js2 10y agoAn identifier is exported if both: 1. the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and 2. the identifier is declared in the package block or it is a field name or method name. All other identifiers are not exported. https://golang.org/ref/spec#Exported_identifiers https://golang.org/ref/spec#Exported_identifiers Both of the characters you asked about are lowercase: http://www.fileformat.info/info/unicode/char/00df/index.htm http://www.fileformat.info/info/unicode/char/00df/index.htm http://www.fileformat.info/info/unicode/char/0138/index.htm http://www.fileformat.info/info/unicode/char/0138/index.htm Here's the full list of Lu characters: http://www.fileformat.info/info/unicode/category/Lu/list.htm http://www.fileformat.info/info/unicode/category/Lu/list.htm
- barsonme 10y agoHere are the rules: https://golang.org/ref/spec#Exported_identifiers https://golang.org/ref/spec#Exported_identifiers An identifier may be exported to permit access to it from another package. An identifier is exported if both: the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and the identifier is declared in the package block or it is a field name or method name. All other identifiers are not exported.
- skj 10y agoDefinitely one or the other, but the confusion means it's best practice to avoid fancy letters for identifiers.
- kuschku 10y agoWell, there's people writing code in other languages. I know in Japan and Germany it's still kinda common for larger companies to build codebases in local languages. Which in turn can lead to these issues.
- gtremper 10y agoTechnically, exported/unexported is different than public/private since its at the package level. You can access unexported fields of a struct from anywhere within the same package (not just from that struct's "methods"), which isn't true of a 'private' field.
- krylon 10y agoIIRC, that is also true for protected members in Java (it has been a while, though, since I have written anything in Java). If that is a concern, you can create a new package for your type.