cron.New().Remove()
code: id := 1 cron.New().Remove(1) cron.New().Remove(id) question:
- The parameter requirement is EntryID, why is 1 possible?
- 1 There is no error, why can't the id?
Hi @tuye01 it's probably a matter of type inference.
The parameter requirement is EntryID, why is 1 possible?
Here you're assigning the numeric literal directly to the argument and therefore the inferred (or implicitly converted?) type corresponds to the required one. This is possible because cron.EntryID is an alias typedef for int.
There is no error, why can't the id?
While here you first assign the literal to id, which makes the variable have type int and then when you call cron.New().Remove(id) the types do not match.
In fact, if you explicitly type the variable var id cron.EntryID = 1 the removal runs as expected.