1

If we were to send

type ABC struct{
      i interface{}

   }

gob requires us to register the concrete type hidden behind our interface{}. Why can't gob use reflection to identify the underlying concrete class in the field by itself.

That is, we need to use the Register method to tell gob what the concrete type is.

Given the method signature looks like this Register(value interface{}), gob already uses reflection to fully identify the type passed to the method.

Why doesn't gob iterate through the instantiated ABC struct at runtime and perform Register automatically?

Robert Jakubowicz
  • 338
  • 1
  • 4
  • 11
  • 1
    Possible duplicate: [Decode gob output without knowing concrete types](https://stackoverflow.com/questions/47071276/decode-gob-output-without-knowing-concrete-types/47071891#47071891). Because decoding may happen in a different running app (on a different computer), and to automate all this would require to transmit the whole type definition which is far from optimal and is prone to type identity errors. – icza Jul 11 '18 at 16:18

0 Answers0