Interface Satisfaction

  • A type satisfies an interface if it implements all the methods the interface requires.
  • *os.File
    • *os.File satisfies io.Reader, Writer, Closer, and ReadWriter.
  • *bytes.Buffer
    • A bytes.Buffer satisfies io.Reader, Writer, and ReadWriter.
    • Does not satisfy Closer as it does not have a Close method.

Assignability(分配) Rule

  • An expression may be assigned to an interface only if its type satisfies the interface. Image

Concealing(隱瞞) the concrete type and value

  • Interface wraps concrete type, only methods defined by interface are revealed even if concrete type implements others.
© Kimi Tsai all right reserved.            Updated : 2023-07-12 09:04:53

results matching ""

    No results matching ""

    results matching ""

      No results matching ""