Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> And how do I get the same type out that I put in?

You can only get out the same type you put in. Presumably in your code you know that collection of Foo objects contains Foos, so you can just do:

    if foo, ok = collection.get().(Foo); !ok {
      return errors.New("expected a Foo")
    }
Write a few wrapper functions and you're done.


So, we’re back in Java 1.0, and using Object and just casting back again?

Seriously, this is why generics exist. I want to write it once, use it everywhere again, and want to have the compiler know if I made a mistake.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: