Last active
October 10, 2017 12:52
-
-
Save inancgumus/3ca06a0af9ebe9abc9a636a2c7754805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
// visible inside main package | |
const packageLevelConst = 1 | |
// visible everywhere | |
const ExportedPackageLevelConst = 2 | |
func main() { | |
// only available to main func | |
const funcLevelConst = 4 | |
// shadowing the const at line #8 | |
const packageLevelConst = 8 | |
// shadowing the const at line #11 | |
const ExportedPackageLevelConst = 16 | |
fmt.Println("funcLevelConst:", funcLevelConst) | |
fmt.Println("packageLevelConst:", packageLevelConst) | |
fmt.Println("ExportedPackageLevelConst:", ExportedPackageLevelConst) | |
fmt.Println("\nWITHOUT SHADOWING:") | |
printWithoutShadowing() | |
} | |
// this doesn't shadow the constants at lines #8 and #11 | |
func printWithoutShadowing() { | |
fmt.Println("packageLevelConst:", packageLevelConst) | |
fmt.Println("ExportedPackageLevelConst:", ExportedPackageLevelConst) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment