Answer the question
In order to leave comments, you need to log in
Why is an array of objects satisfying an interface not cast to an array of those interfaces?
There is a function common to several types:
type logged interface {
GetLogID() int64
}
func maxLogID(items []logged) int64 {
max := int64(0)
for _, item := range items {
if item.GetLogID() > max {
max = item.GetLogID()
}
}
return max
}
type A struct {
logID int64
}
func (a A) GetLogID() int64 {
return a.logID
}
print(maxLogID(make([]A, 0)))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question