What are the differences between each declaration and the consequences for each?

List listOne = new LinkedList<Shxx>();      
List<Shxx> listTwo = new LinkedList<Shxx>();
List listThree = new LinkedList();
List<Shxx> listFour = new LinkedList();
+3
source share
2 answers
List listOne = new LinkedList<Shxx>();

Discards type information, may also not use generic types.

List<Shxx> listTwo = new LinkedList<Shxx>();

Fix the full use of generics, ensure type safety.

List listThree = new LinkedList();

No use of generics (i.e. pre Java 5 code), no type security.

List<Shxx> listFour = new LinkedList();

, OK, . , , , , raw, , , . - .

+7

listOne listThree ( , IDE , instanciation listOne , instanciation listThree , ).

(String ).

listTwo List Shxx.

Shxx.

listFour (, listTwo) List of Shxx ( ​​).

, , , Runtime ( ).

+1

Source: https://habr.com/ru/post/1769299/


All Articles