unhashable type []interface #57

Closed
opened 2017-04-11 07:18:01 +00:00 by nifflin · 1 comment
nifflin commented 2017-04-11 07:18:01 +00:00 (Migrated from github.com)

type HashSet struct { set *hashset.Set }

func NewHashSet() *HashSet { var result HashSet result.set = hashset.New() return &result }

// If call Add("abc"), it will crash and output "unhashable type []interface", why? func (s *HashSet) Add(items ...interface{}) { s.set.Add(items) }

Thank you.

type HashSet struct { set *hashset.Set } func NewHashSet() *HashSet { var result HashSet result.set = hashset.New() return &result } // If call Add("abc"), it will crash and output "unhashable type []interface", why? func (s *HashSet) Add(items ...interface{}) { s.set.Add(items) } Thank you.
icecity96 commented 2017-05-02 09:30:41 +00:00 (Migrated from github.com)

There is no problem with gods. The reason cause this problem is the way you use ...interface{} try following:

func (s *HashSet) Add(items ...interface{}) {
		s.set.Add(items...)
}

or

func (s *HashSet) Add(items ...interface{}) {
	for _,item := range items {
		s.set.Add(item)
	}
}

There is no problem with `gods`. The reason cause this problem is the way you use ...interface{} try following: ``` func (s *HashSet) Add(items ...interface{}) { s.set.Add(items...) } ``` or ``` func (s *HashSet) Add(items ...interface{}) { for _,item := range items { s.set.Add(item) } } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods#57
No description provided.