M
M
Maxim Petelin2017-10-18 13:02:38
go
Maxim Petelin, 2017-10-18 13:02:38

How to work with a dynamic list in GO?

The code below throws an error:
invalid operation: x < e.Value (operator < not defined on interface)

package main

import (
  "container/list"
  "fmt"
)

func main() {
  var l list.List
  
  l.PushBack(1)
  l.PushBack(2)
  l.PushBack(3)
  l.PushBack(4)
  
  x := 2

  for e := l.Front(); e != nil; e = e.Next() {
    if x < e.Value {
      fmt.Println(e.Value)
    }
  }
}

reflect.TypeOf for both x and e.Value indicates the data type int
How to do it right, print the numbers 3 and 4?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-10-18
@petelinmn

if x > e.Value.(int) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question