The point freeformz is making is that you loose compile time type safety. 
Your program can still be made type safe at runtime (i.e. not panic) but 
it's a cop out. Sometimes it is worth it since Go type system is limited in 
comparison of its reflection lib which basically allows anything, sometimes 
it isn't. interface{} means turning Go into a dynamic language.

Le mardi 8 novembre 2016 01:09:10 UTC+1, Michael Jones a écrit :
>
> Not precisely so…Interfaces, and type switches, and related mechanisms are 
> safe. Their type indeterminism is protected from the program and their 
> concretization is much like Schrodinger’s box…the interface is any type 
> until you look at it through a type switch or type dereferencing…then it is 
> a living concrete type of an expected type or else, like the cat, your 
> program is dead. 
>
>  
>
> *From: *<golan...@googlegroups.com <javascript:>> on behalf of Edward 
> Muller <edwa...@interlix.com <javascript:>>
> *Date: *Monday, November 7, 2016 at 4:05 PM
> *To: *Kaylen Wheeler <kfjwh...@gmail.com <javascript:>>, golang-nuts <
> golan...@googlegroups.com <javascript:>>
> *Subject: *Re: [go-nuts] Noob question: Pointers to interfaces
>
>  
>
> FWIW: As soon as interface{} is involved you are no longer "type safe".
>
>  
>
> On Mon, Nov 7, 2016 at 2:56 PM Kaylen Wheeler <kfjwh...@gmail.com 
> <javascript:>> wrote:
>
> So, what I'm trying to accomplish is a little unusual, and may need some 
> explanation.
>
> Basically, I'm trying to find a typesafe way to access a type-indexed map 
> of components.  This map can contain objects of any type, and the keys are 
> reflect.Type.
>
> One strategy I thought may work would be to pass a pointer to a pointer as 
> an out-var.  Using reflection to determine the pointer's type, it could be 
> populated with a corresponding value.
>
> For instance, if we did something like this:
>
> c := ComponentCollection{}
> c.addComponent(123) // Add an int component
>
> var p : *int
> c.getComponent(&p)
>
>
> In this case, p would point to the int component of c.
>
> That's wht the 2 levels of indirection are necessary: it's an out-var to a 
> pointer.
>
> Does that make sense?
>
> --
> 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...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
> -- 
> 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...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to