FAQ
I have a article struct
type Article struct{
Tags []Tag
}
func (a *Article) Tags() {
}
it's has a error that "type Article has both field and method named Tags"
when i build it.
Why is such a design?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Jan Mercl at Sep 2, 2014 at 3:28 pm

    On Tue, Sep 2, 2014 at 5:24 PM, Brain Wu wrote:
    I have a article struct
    type Article struct{
    Tags []Tag
    }
    func (a *Article) Tags() {
    }
    it's has a error that "type Article has both field and method named Tags"
    when i build it.
    Why is such a design?
    Consider

    var v Article
    var u = v.Tags

    What type is u? '[]Tag' or 'func(*Article)'?

    -j

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • 吴俊滨 at Sep 2, 2014 at 3:31 pm
    i got it. thank you very much
    在 2014年9月2日,下午11:28,Jan Mercl <0xjnml@gmail.com> 写道:
    On Tue, Sep 2, 2014 at 5:24 PM, Brain Wu wrote:
    I have a article struct
    type Article struct{
    Tags []Tag
    }
    func (a *Article) Tags() {
    }
    it's has a error that "type Article has both field and method named Tags"
    when i build it.
    Why is such a design?
    Consider

    var v Article
    var u = v.Tags

    What type is u? '[]Tag' or 'func(*Article)'?

    -j
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Chris dollin at Sep 2, 2014 at 3:36 pm

    On 2 September 2014 16:24, Brain Wu wrote:
    I have a article struct
    type Article struct{
    Tags []Tag
    }
    func (a *Article) Tags() {
    }
    it's has a error that "type Article has both field and method named Tags"
    when i build it.
    Why is such a design?
    As a general rule [1], Go doesn't let you declare the same name more
    than once in the same scope, so that if you have the name, you know
    what thing it is.

    Similarly Go doesn't allow function/method overloading.

    Chris

    [1] Apart from the redeclaration feature of :=, a topic of hot discussion.

    --
    Chris "allusive" Dollin

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 2, '14 at 3:24p
activeSep 2, '14 at 3:36p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase