android - Last variable in arraylist is overriding all variables -


this productcatalogclass :

public class productcatalogclass {     private arraylist<productclass> productlist;      public arraylist addproduct() {                  // ...         return productlist;        } } 

this productclass :

public class productclass {     private string productname;     private string availability;     private int price;      // getters , setters } ... 

how should resolve this? i know of methods not completed can't finish until figure out how fix arraylist issue

when add product productlist, reference object added (something pointers in c). if add same object list ten times, have list of ten references 1 object.

you should create new product every time want add list.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -