Question: Whoa, are there really versions of Go with generics? I just have a hard time accepting empty interfaces but eschewing generics

Asked By
Asked At
2017-09-28 22:55:23

Found 15 possible answers.

User Answered At Possible Answer
brunocassol 2017-09-28 22:56:17 One has to appreciate the amount of pondering and experimentation that the Go team exercises before shoving new features like other programming languages do.
exbigboss 2017-09-28 22:56:18 It eludes me
theo.dano 2017-09-28 22:56:58 @brunocassol you can't really say that ... look how much time it takes to C++ or Java to implement things 3 years for C++
exbigboss 2017-09-28 22:57:23 And even then, many things were pushed back from C++17 so they could be more thought out Hence, lol no modules and lol no concepts Like modules and concepts
dlsniper 2017-09-28 22:57:34 please move it to #general it's out of newbies space :wink:
exbigboss 2017-09-28 22:57:53 Fair enough
itzikbenh 2017-09-28 23:11:03 Hey, Not sure what data type I should use.
    Payload string `json:"payload"`
    Topic   string `json:"topic"`
    Event   string `json:"event"`
This is an empty JavaScript object at the moment.
type Event struct { I'm getting json: cannot unmarshal object into Go struct field Event.payload of type string
gopher 2017-09-28 23:11:04 The above code in playground:
itzikbenh 2017-09-28 23:30:24 This seems to do the job for now. map[string]string
genez 2017-09-29 08:51:54 @itzikbenh please post a sample json and/or test it with this amazing online tool: from the error message it seems to me that the payload value has curly brackets and json un-marshaler is trying to convert it into a struct, not a string
theckman 2017-09-29 09:16:54 Almost, it's saying the JSON data isn't a string so it can't be loaded in to the struct field Event.Payload. Inspecting the JSON is the only way.
igorkim 2017-09-29 09:34:19 Hi, i have a function which must return slice of objects with different types so i have no choice but to return interface{} as params. How bad is that?
theckman 2017-09-29 09:35:54 Not bad, you lose type safety at compile time.
genez 2017-09-29 10:03:29 igor, maybe you can extract a common interface for the types in your slice, so you get a slice of well-defined intarfaces
aditza8 2017-09-29 10:57:24 This is the weirdest type I saw so far
as `map[chan<-string]struct{}", so is not a channel, or a primive type is ...

Related Questions