<p>a code example could be like</p>
<p>package demo</p>
<p>type priv struct{}</p>
<p>func Demo() priv{
return priv{}
}</p>
<hr/>**评论:**<br/><br/>binaryblade: <pre><p>That unexported type could satisfy a visible interface.</p></pre>TheMerovius: <pre><p>See <a href="https://godoc.org/encoding/binary#pkg-variables" rel="nofollow">encoding/binary</a> for an example of how exposing unexported types can be useful.</p></pre>mrkaspa: <pre><p>Thanks!</p></pre>materialdesigner: <pre><p>Because nothing in go is "private"/"public", it's "unexported"/"exported". It might seem like an unimportant difference but this is exactly why. </p>
<p>What is the use case? One use case is to only expose a Smart Constructor that doesn't let you create a struct with meaningless or uninitialized values. But it is frowned upon by tools like golint</p></pre>dilap: <pre><p>Not that useful though, because in the calling package you can't write down the type, meaning you can only use the result within a single functions scope:</p>
<p>x := p.Demo() // returns a private type</p>
<p>I don't see it so much as "why does it allow" but more "no reason to disallow".</p></pre>RalphCorderoy: <pre><p>Do you mean <code>func demo</code> to have a capital D?</p></pre>mrkaspa: <pre><p>Yes sorry, I updated it</p></pre>THEHIPP0: <pre><p>You can use this function from within the package from another function. Also the function is private too.</p></pre>dlsniper: <pre><p>Demo() is exported from package demo since it starts with a capital letter.</p></pre>
![](https://static.golangjob.cn/static/img/banner.png)