This question already has an answer here:
while going through this tutorial on writing FUSE filesystems in go, I came across this cryptic assignment:
var _ fs.Node = (*Dir)(nil)
Can someone explain the mechanics of this syntax, and how does it fit in the context in which it is declared? As I understand the outcome of the assignment is actually ignored (and what does the right hand expression even result in? a nil Dir pointer?)
</div>
This makes the compiler check if type *Dir
fulfills fs.Node
interface.
Take a nil
pointer, make it a *Dir
pointer and assign it to an unnamed variable of interface type fs.Node
. Since we never use this variable, we have to make it unnamed.