Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'd like it you could set what class this

var strings = { "red", "green", "blue" }

uses. In some clean way. eg I don't want List, I want ArrayList.



You can do that the way you'd expect:

    var strings = new ArrayList<String>() { "red", "green", "blue" }


Thanks. That's interesting. Is there a global setting to always use ArrayList instead of List? Actually maybe global is too much... per file setting.


So by default the type inferred is ArrayList, if you want a different type you just specify it.

ex. var strings = { "red", "green", "blue" } //ArrayList

var strings2 : LinkedList<String> = { "red", "green", "blue" }


thanks




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: