setting the type of an empty list
Posted: Mon Aug 16, 2010 1:09 pm
Chuck I know you are busy with the Java backend, so I didn't want to bother with this question which may have a trivial answer that I don't know about. So maybe the community can help me out here:
gives me the error:
Cannot implicitly convert type "System.Collections.Generic.List<object>" to "System.Collections.Generic.List<int>"
Somehow I need to tell the compiler that 'r' is a list of ints when I initialize it. Because when I change the above to 'r = [2]' (or any other int in place of 2) it works. I tried 'r = int[]' but that didn't seem to work. Also did not find anything on how to set the type of an empty list on this page: http://cobra-language.com/how-to/UseLists/
Thanks for any help you can provide.
- Code: Select all
class Prog
def main
print .add([1, 2, 3], 4)
def add(a as List<of int>, b as int) as List<of int>
r = []
for v in a
v = v + b
r.add(v)
return r
gives me the error:
Cannot implicitly convert type "System.Collections.Generic.List<object>" to "System.Collections.Generic.List<int>"
Somehow I need to tell the compiler that 'r' is a list of ints when I initialize it. Because when I change the above to 'r = [2]' (or any other int in place of 2) it works. I tried 'r = int[]' but that didn't seem to work. Also did not find anything on how to set the type of an empty list on this page: http://cobra-language.com/how-to/UseLists/
Thanks for any help you can provide.