May 21, 2021 01:26 pm GMT
Original Link: https://dev.to/baenencalin/is-there-a-way-to-have-custom-typecasting-in-golang-383b
Is there a way to have custom typecasting in GoLang?
I know there is typecasting in GoLang, such as:
type long int64;type ulong uint64;var l long = 39486;var i16 = int64(l);var ui16 = uint64(i16);fmt.Println( string([]byte {100, 150, 125, 68, 66}) );
But is there a way to add them to interface/struct types?
type IJType interface {/* ... */}type JByte struct {/* Implements IJType */}
Is there a way I could make a constructor, like in the following?
var j JByte = JByte(255 /*byte*/); // -> JByte(byte) -> JByte {/* ... */}byte(j); // 255.
Original Link: https://dev.to/baenencalin/is-there-a-way-to-have-custom-typecasting-in-golang-383b
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To