I try use List instead of List
List<?> list = new ArrayList<Integer>();
...
list.add(1); //compile error
What i do wrong and how cast new value to Integer?
Maybe i shoud use List in my project?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
List<?>means a list of some type, but we don’t know which type. You can only put objects of the right type into a list – but since you don’t know the type, you in effect can’t put anything in such a list (other thannull).There is no way around this, other than declaring your variable as
List<Integer>.