What is the difference in calling an interface methods and struct methods in serveHTTP handler?

user5906464 :

I'm moving from Java to go. In 'go', I got confused when using a Handler.

For eg: ServeHTTP(w http.ResponseWriter, req *http.Request)

Here ResponseWriter is an interface and Request is a struct. We are using w as an object to call the methods in ResponseWriter interface. The same goes with req object. I know that a struct can implement an interface. Here I'm showing an example and where I'm getting confused. Go Playground Link

Adrian :

There's no difference. The interface is the type of your variable/field/parameter; the value is still (most likely) a struct. This is the same as in Java, where you can specify that a method argument is of an interface type, but you must still pass in a concretion. Calling methods on the interface-typed argument is the same as calling the method on a concrete type.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the use of calling Interface methods in the implemented class?

From Dev

What is the difference between COM property methods and regular interface methods?

From Dev

What is performance difference between different class or struct initialization methods?

From Dev

What's the difference between "=>" operator and {} when calling any methods?

From

Calling methods on interface pointers in Go

From Dev

What is difference between abstract class with all abstract methods and interface(not technically)

From Java

What is the difference between setter methods and constructor methods?

From Java

What is the difference between inherited methods and public methods?

From Dev

What are IBinarySerialize Interface methods used for?

From

Types of Go struct methods that satisfy an interface

From Dev

How to define interface for methods on struct pointer

From Dev

Avoiding downcasting when calling interface methods

From Dev

Struggling with calling overloaded methods from interface to class

From Java

What is the difference between these two methods

From Dev

what is the difference between these two methods?

From Dev

What is the difference between these awaitable methods?

From Dev

What is the difference between these methods in class

From Dev

Default Interface Methods. What is deep meaningful difference now, between abstract class and interface?

From Dev

What is the difference of calling methods between in derived function and with new key word in Solidity?

From Dev

How Variable of an Interface is Working in JAVA and Calling the Methods of Interface?

From Java

Interface with no methods

From

Methods of an interface

From Dev

What's the difference between class methods and instance methods in Swift?

From Dev

What's the difference between Custom model manager methods and QuerySet methods?

From Dev

What is difference between global methods and instance methods in Vue.js?

From Dev

what is the difference between a function that returns an object with methods and a variable that is an object with methods

From Java

Final arguments in interface methods - what's the point?

From Dev

How to have a struct that accepts closures calling methods from another variable?

From

What is the difference between an interface and a class, and why I should use an interface when I can implement the methods directly in the class?

Related Related

  1. 1

    What is the use of calling Interface methods in the implemented class?

  2. 2

    What is the difference between COM property methods and regular interface methods?

  3. 3

    What is performance difference between different class or struct initialization methods?

  4. 4

    What's the difference between "=>" operator and {} when calling any methods?

  5. 5

    Calling methods on interface pointers in Go

  6. 6

    What is difference between abstract class with all abstract methods and interface(not technically)

  7. 7

    What is the difference between setter methods and constructor methods?

  8. 8

    What is the difference between inherited methods and public methods?

  9. 9

    What are IBinarySerialize Interface methods used for?

  10. 10

    Types of Go struct methods that satisfy an interface

  11. 11

    How to define interface for methods on struct pointer

  12. 12

    Avoiding downcasting when calling interface methods

  13. 13

    Struggling with calling overloaded methods from interface to class

  14. 14

    What is the difference between these two methods

  15. 15

    what is the difference between these two methods?

  16. 16

    What is the difference between these awaitable methods?

  17. 17

    What is the difference between these methods in class

  18. 18

    Default Interface Methods. What is deep meaningful difference now, between abstract class and interface?

  19. 19

    What is the difference of calling methods between in derived function and with new key word in Solidity?

  20. 20

    How Variable of an Interface is Working in JAVA and Calling the Methods of Interface?

  21. 21

    Interface with no methods

  22. 22

    Methods of an interface

  23. 23

    What's the difference between class methods and instance methods in Swift?

  24. 24

    What's the difference between Custom model manager methods and QuerySet methods?

  25. 25

    What is difference between global methods and instance methods in Vue.js?

  26. 26

    what is the difference between a function that returns an object with methods and a variable that is an object with methods

  27. 27

    Final arguments in interface methods - what's the point?

  28. 28

    How to have a struct that accepts closures calling methods from another variable?

  29. 29

    What is the difference between an interface and a class, and why I should use an interface when I can implement the methods directly in the class?

HotTag

Archive