How can I access stored values of a Bean from inside another Class

前端 未结 1 730
独厮守ぢ
独厮守ぢ 2020-12-29 15:44

How can I implement this functionality?

ApplicationConstants.phoneContacts.add(
  new ContactNumberBean(nameOfContact,
    contactNumber, contactNumberType))         


        
相关标签:
1条回答
  • 2020-12-29 16:35

    hi to access been values in another class create a common class named as Constants.java in that declare and initialize been object like below:

    public class Constants{
    
        public static Bean userBeen=new Bean();
    
    }
    

    been class:

    public class Been {
    
        private string countryName;
    
        public void setCountry(String s) {
            this.countryName=s;
        } 
    
        public String getCountry() {
            return countryName;
        }
    }
    

    set values:

    public class A{
    
        String s="India";
    
        Constants.userBeen.setCountry(s);
    
        }
    }
    

    get values:

    public class B{
    
        String s=Constants.userBeen.getCountry();
    
        }
    
    }
    

    this will work fine.

    0 讨论(0)
提交回复
热议问题