Skip to content

Instantly share code, notes, and snippets.

@r2p2
Created November 29, 2011 20:44
Show Gist options
  • Select an option

  • Save r2p2/1406421 to your computer and use it in GitHub Desktop.

Select an option

Save r2p2/1406421 to your computer and use it in GitHub Desktop.
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