Quantcast
Channel: How to declare an immutable variable in Go? - Stack Overflow
Browsing all 3 articles
Browse latest View live

Answer by Zombo for How to declare an immutable variable in Go?

For something with similar result, you could use a private field. Make a modulelike this:package footype Length struct { value int }func NewLength(s string) Length { return Length{ len(s), }}func (l...

View Article



Answer by Hymns For Disco for How to declare an immutable variable in Go?

You cannot specify a variable to be immutable. Only constants have this property.Constants in Go are also compile-time constant, meaning you can't initialize it to something that depends on the...

View Article

How to declare an immutable variable in Go?

I was solving some exercises to get some practice in go and came across thefollowing problem.Take this function:func foo(s string) { length := len(s); // Do something just reading from lenght}Here,...

View Article
Browsing all 3 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>