Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. package main
  2.  
  3. type Interface interface {
  4. }
  5.  
  6. type A struct {
  7. }
  8.  
  9. type B struct {
  10. }
  11.  
  12. func id(i Interface) Interface {
  13. return i
  14. }
  15.  
  16. func withA(a A) {
  17. }
  18. func withB(b B) {
  19. }
  20.  
  21. func main() {
  22. a, ok := id(A{}).(A)
  23. if ok {
  24. withA(a)
  25. }
  26. b, ok := id(B{}).(B)
  27. if ok {
  28. withB(b)
  29. }
  30. c, ok := id(B{}).(A)
  31. if ok {
  32. withA(c)
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement