+ 1

wrong question

It's a wrong thing in this question which wrote List <string> list = new ArrayList<string>();

12th Feb 2017, 12:47 PM
Mohammad Mirshekar
Mohammad Mirshekar - avatar
1 Respuesta
0
No, its not, although it may not have been taught in these SoloLearn lessons. List<String> is an interface, which specify functions a List must have. You know, indexing, iterator, and such things. The ArrayList class implements the List interface by using dinamically sized arrays hidden from you. So the ArrayList class is an array-based implementation of the List interface. So, as the following works: Object list = new ArrayList<String>(); The one you mentioned will also work. It depends on the programmer, but I think it depends on how did you learn it and practiced. Some people initialize lists only into list typed variables, because they only need the list functionality. And that is fine, if someone replaces it with a LinkedList, for example, it will still work as planned. On the other hand, if you provide the list from a function as return type it is better to pass as ArrayList instead of just List, because it is more specific and no need for output abstraction. However, the lowercase "string" is not valid, it must be "String" to represent the String class of java, not like (for example) in C#, where "string" is also valid for that base class.
25th Apr 2017, 5:26 PM
Magyar Dávid
Magyar Dávid - avatar