#917 Creating a function that will accept a List of any type

fury Sat 16 Jan 2010

I read the generics entry, but I'm not really sure I understood it correctly. I tried to create a method like this:

static Str commify(L list)
{
  result := ""
  list[0..<list.size-1].each |v| { result += v + "," }
  result += " and ${list[list.size-1]}"
  return result
}

it didn't work. It said that L was an unknown type. I also tried to specify the type as L[]. It still didn't work. Is there another way of writing a method that will take a List of any type, or do I have to set the type of the list parameter to Obj[]?

brian Sat 16 Jan 2010

To accept a list of any type use Obj?[], or Obj[] if you want to disallow nulls.

Login or Signup to reply.