If someone is interested I simplified the code, commented some more and added the unmarshall json in the example - https://go2goplay.golang.org/p/I_ezQ9wyWVx.
Still, I don't know how to type the BuildEmptySpec() in BoxBaseI better than to return a simple interface{}... If it would return BoxSpecI(BoxBaseI) it would not be enough. Aleksandar On Fri, Jul 3, 2020 at 1:54 PM Aleksandar Milovanović < aleksan...@videobolt.net> wrote: > Hi guys, > > Thanks for the effort, it is much needed for quite some time. I really > appreciate the way of introducing the changes, go2go tool and open > discussion, so I wanted to review them and participate with feedback so you > can do the best job of understanding the world. With proposed changes, I > think extending language to support something similar to polymorphism might > be cheap. > > Consider this go playground: https://go2goplay.golang.org/p/jqA4ccWeAKD. > > Syntax is awkward currently (some syntax sugar is definitively needed), > but the point in the test below stands - you do have polymorphic slice, you > can use base fields and methods, and you can cast to the child structure > (which contains all the fields and methods from the base). json marshaling > was added to the example, json unmarshal could be implemented similarly, > but in that case we need provided mapping from base structure to the > specialized one, which can't be typed with current generics (for some of > it, interface{} and reflect would be needed). Could provide that example as > well, if needed. > > Sending this idea as I think it might be interesting, and I think you > might get some more ideas out of it. > > Aleksandar > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAG9NSAWtK%3DeUR9%2B_vCb0X5yun6VF3SB6WOkfq5%2B-cX7KXNQ9vg%40mail.gmail.com.