You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"bytes"
"gob"
"log"
)
type T int
func main() {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
dec := gob.NewDecoder(&buf)
var t T = 2
if err := enc.Encode(t); err != nil {
log.Exitf("encode: %v", err)
}
var i interface{}
if err := dec.Decode(&i); err != nil {
log.Exitf("decode: %v", err)
}
}
$ 6.out
2010/11/15 15:42:38 decode: gob: wrong type received for local value interface { }
$
The text was updated successfully, but these errors were encountered:
Gobs do not implement Go assignment rules. If you want the receiver to decode into an
interface, you must send an interface. Otherwise the receiver doesn't in general have
the necessary information to store the concrete value. There are cases, like this one,
in which one could argue that the system should be able to work it out, but in general
it cannot, so that's not the semantics of gobs.
The text was updated successfully, but these errors were encountered: