写两个方法分别设置两个字段:public void setTitle(String value){
    this.title = value;
}
public void setText(String value){
    this.text = value;
}

解决方案 »

  1.   

    this.title="mytitle";
    this.text="mytext";
    有无限多个,我就是想把他抽成共用函数.
      

  2.   

    无限多个??要这么多成员变量干嘛,考虑一下用数组或ArrayList之类的另外,对于一个成员变量,就应该有一个设置方法,不能抽成公用函数
      

  3.   

    具体怎么操作啊?用title和text帮我做个范例吧,谢谢
      

  4.   

    //成员变量
    HashMap map = new HashMap();public void setValue(Object key,Object value){
        map.put(key,value);
    }public Object getValue(Object key){
        return map.get(key);
    }这样设置title和text,就可以用方法:
    setValue("title","mytitle");
    setValue("text","mytext");
    取title和text的值可以用方法:
    getValue("title");
    getValue("text");
    注意返回的是Object,根据你的需要进行类型转换