Project Structure
├── cmd
│ └── main.go
├── go.mod
└── internal
└── testt
main.go
// main.go
package main
import (
"fmt"
"example.com/myproject/internal/testt"
)
// Define a struct abhi
type abhi struct {
value string
}
// Implement Can_do method for abhi
func (a *abhi) Can_do() {
fmt.Println("abhi_can_do")
}
// Implement small method for abhi
func (a *abhi) small() {
fmt.Println("small")
}
func main() {
var a abhi
var b testt.Nandu_test
b = &a
b.Can_do()
b.Can_do()
}
testt.go
package testt
type Nandu_test interface {
Can_do()
small()
}
error find the images
error Image
Error: cannot use &a (value of type *abhi) as testt.Nandu_test value in assignment: *abhi does not implement testt.Nandu_test (unexported method small)compilerInvalidIfaceAssign
I would like to know why this is happening how the packages work
0
The specification says:
Two identifiers are different if they are spelled differently, or if they appear in different packages and are not exported.
The small
identifiers used in main.abhi
and testt.Nandu_test
are different identifiers. It follows that main.abhi
does not implement the testt.Nandu_test
interface.
James Bowman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.