Created
November 29, 2011 20:44
-
-
Save r2p2/1406421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "image" | |
| func draw(i *image.Image) { | |
| //main.go:8: i.Bounds undefined (type *image.Image has no field or method Bounds) | |
| // But Interface Image says that Bounds has to be | |
| // implemented. | |
| i.Bounds() | |
| } | |
| func main() { | |
| img := image.NewRGBA(123,321) | |
| /* first try */ | |
| // main.go:13: cannot use img (type *image.RGBA) as type *image.Image in function argument: *image.Image is pointer to interface, not interface | |
| // me: where is your type inference? Thought there are interfaces for?!?! | |
| //draw(img) | |
| /* second */ | |
| // main.go:23: cannot use image.Image(img) (type image.Image) as type *image.Image in function argument: *image.Image is pointer to interface, not interface | |
| // me: that sounds logical | |
| //draw(image.Image(img)) | |
| /* third */ | |
| // main.go:29: cannot convert img (type *image.RGBA) to type *image.Image | |
| // me: found this solution by gooleling around. | |
| draw((*image.Image)(img)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment