java - How do I set and get a Vector<Integer> in two different classes? -


i need set , vector in 2 different classes seem losing size of vector in process. if v.size() 100 example. use setter. in class use getter access vector again. if v.size() in new class 0. below code rough example of have, can't copy paste code exactly, since it's part of larger private project.

public class params {     private vector<integer> _v = new vector<integer>();     public vector<integer> get_v(){return _v;}     public void set_v(vector<integer> _v){this._v = _v;} }  public class {     v.add(10);     system.out.println(v.size()); //returns 1     params p = new params();     p.set_v(v); }  public class b {     params p = new params();     v = p.get_v();     system.out.println(v.size()); //returns 0 } 

when make params = new params() on b create new object of class params, , new object initializes new empty vector on _v property.

you should pass object created on a b class can use it.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -