collections - How do I declaratively create a list in Scala? -
in c# can declare list declaratively, in other words declare structure , initialise @ same time follows:
var users = new list<user> { new user {name = "tom", age = 12}, new user {name = "bill", age = 23} };
ignoring differences between list in .net , list in scala (ie, feel free use different collection type), possible similar in scala 2.8?
update
adapting thomas' code below believe nearest equivalent c# code shown:
class user(var name: string = "", var age: int = 0) val users = list( new user(name = "tom", age = 12), new user(name = "bill", age = 23))
what about:
case class user(name: string, age: int) val users = list(user("tom", 12), user("bill", 23))
which give you:
users: list[user] = list(user(tom,12), user(bill,23))
Comments
Post a Comment