On Sunday, 28 February 2021 at 03:03:17 UTC Deiter wrote:

> The example uses a “short assignment” statement, so it’s not obvious what 
> “concrete” type c.StdoutPipe() returns
>

You can't tell, and indeed it might not return any concrete type at all (it 
may return nil).

Given

stdout, err := cmd.StdoutPipe()

then the types of those variables are exactly the types of the values 
returned by StdoutPipe, i.e. stdout is of type "io.ReadCloser" and err is 
of type "error".  Both of these happen to be interface types.

The important thing to note is that a variable can have a static type which 
is "an interface type". At runtime, it can hold any value of any concrete 
type which implements that interface - or "nil", which is the zero value of 
an interface type.  If the interface value is not nil, then the concrete 
value is boxed in such a way that you can invoke the interface methods.

However, given

rPipe, _ := io.Pipe()

then the type of variable rPipe is "*PipeReader", which is a pointer to a 
concrete 
type <https://golang.org/pkg/io/#PipeReader>.  The only thing you can 
assign to variable rPipe is a value of type *PipeReader.  Somewhat 
confusingly, pointer values can also be "nil", but a nil pointer value is 
not the same thing as a nil interface value.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e85ba460-2b04-4357-acbf-561db8c48959n%40googlegroups.com.

Reply via email to