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: <golang-nuts@googlegroups.com> on behalf of Edward Muller 
<edwar...@interlix.com>
Date: Monday, November 7, 2016 at 4:05 PM
To: Kaylen Wheeler <kfjwhee...@gmail.com>, golang-nuts 
<golang-nuts@googlegroups.com>
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 <kfjwhee...@gmail.com> 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+unsubscr...@googlegroups.com.
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.


-- 
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