Laird Nelson
Laird Nelson

Reputation: 16238

Is this a special form of Go type assertion?

I am a total novice Go programmer.

I ran across this in the Kubernetes source code:

var (
  _ = Queue(&FIFO{}) // FIFO is a Queue
)

Queue is declared earlier like this:

type Queue interface { // etc.

FIFO is declared earlier like this:

type FIFO struct { // etc.

So is my first excerpt a kind of type assertion? It doesn't seem to fit the syntax described by the Go Tour's lesson-let on the subject.

I certainly can take it on faith that this block is ensuring that a FIFO "is a" Queue, but I want to understand exactly what's going on here, and I am too much of a novice to know where to look in the Go language specification (the section on type assertions, which seems to be what this is semantically, didn't seem to cover this case, nor did the section on interface types).

Upvotes: 1

Views: 109

Answers (1)

Corey Ogburn
Corey Ogburn

Reputation: 24769

It's a Type Conversion which is a little different than a type assertion.

Upvotes: 4

Related Questions