FAQ
What does it mean to embed an interface into a struct ?

In the following example (http://play.golang.org/p/X4IyCwSmyd), embedding
the interface into the struct leads to a runtime error
rather than a compile time one. why ?

Is there a use case where you need to do such a thing ?

--
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/groups/opt_out.

Search Discussions

  • Ian Lance Taylor at Jan 16, 2014 at 8:23 pm

    On Thu, Jan 16, 2014 at 11:56 AM, Jonathan Calmels wrote:
    What does it mean to embed an interface into a struct ?

    In the following example (http://play.golang.org/p/X4IyCwSmyd), embedding
    the interface into the struct leads to a runtime error
    rather than a compile time one. why ?

    Is there a use case where you need to do such a thing ?
    Embedding an interface is just like embedding a field of any other
    type. The struct inherits the methods of the interface.

    Ian

    --
    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/groups/opt_out.
  • Rodrigo Kochenburger at Jan 16, 2014 at 8:39 pm
    When you embed an interface into a struct you're expected to set that
    interface w/ a concrete implementation, otherwise what would
    struct.dostuff() execute?

    For example: http://play.golang.org/p/fWN1sJ8Ydy

    - RK

    On Thu, Jan 16, 2014 at 11:56 AM, Jonathan Calmels wrote:

    What does it mean to embed an interface into a struct ?

    In the following example (http://play.golang.org/p/X4IyCwSmyd), embedding
    the interface into the struct leads to a runtime error
    rather than a compile time one. why ?

    Is there a use case where you need to do such a thing ?

    --
    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/groups/opt_out.
    --
    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/groups/opt_out.
  • Jonathan Calmels at Jan 16, 2014 at 8:59 pm
    Ok, I get it now :)

    Thanks !
    On Thursday, January 16, 2014 9:39:12 PM UTC+1, Rodrigo Kochenburger wrote:

    When you embed an interface into a struct you're expected to set that
    interface w/ a concrete implementation, otherwise what would
    struct.dostuff() execute?

    For example: http://play.golang.org/p/fWN1sJ8Ydy

    - RK


    On Thu, Jan 16, 2014 at 11:56 AM, Jonathan Calmels <jbjca...@gmail.com<javascript:>
    wrote:
    What does it mean to embed an interface into a struct ?

    In the following example (http://play.golang.org/p/X4IyCwSmyd),
    embedding the interface into the struct leads to a runtime error
    rather than a compile time one. why ?

    Is there a use case where you need to do such a thing ?

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 16, '14 at 7:56p
activeJan 16, '14 at 8:59p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase