1

I have a pojo class name User. Now I am creating ArrayList of User's class using following statement.

ArrayList<User> userArrayList = new ArrayList();

I have another class whose constructure accept a arraylist of Object i.e.

 public className(ArrayList<Object> objectArrayList){
 }

Now if I want to pass userArrayList into objectArrayList then what conversion should I need to use

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Arjun
  • 736
  • 1
  • 8
  • 24
  • Why would you want to turn it into an object? Seems to me, either use generics or redesign your API. – ifly6 Feb 26 '18 at 17:48
  • Im not sure exactly what you are asking, but everything inherits from `Object`, so no conversion is necessary to pass it. To do things inside your function conversion is necessary. – Hypnic Jerk Feb 26 '18 at 17:48
  • @HypnicJerk, I know every class in Java is inherits from base Object, class but then also it is giving me an error. – Arjun Feb 26 '18 at 17:51
  • @ifly6 , yes I am creating a kind of generic class for a component called RecylcerView's adapter in Android. – Arjun Feb 26 '18 at 17:52
  • chagne your second class declaration to `public className(ArrayList> objectArrayList){ }` – Alanpatchi Feb 26 '18 at 17:52
  • @Sotirios ,Thank you for duplicate links, my problem is solved now :) – Arjun Feb 26 '18 at 18:00

0 Answers0