是否可以在不同的文件中有两个同名的常量?
foo.go
const {
deviceId = 1 // I dont need this outside the file scope
}
type DeviceA struct {
.. some fields..
// I cannot make constant fields here
}
.. some methods ...
bar.go
const {
deviceId = 2 // I dont need this outside the file scope
}
type DeviceB struct {
.. some fields ..
// I cannot make constant fields here
}
.. some methods ...
如果我这样做,我会得到它deviceId已被重新声明。如何将这些常量保留在文件的范围内?
如果可以解决这个问题,我不介意为常量使用某种命名空间。
慕码人8056858
海绵宝宝撒
相关分类