比如一个类 a 他 api里有 setcolor 和 setbook  两个方法
我 A  a  =  new  A();
然后我 a.setcolor  是可以的把
如果我要book 我就是 a.setbook
但是这里怎么有这么多set啊
怎么能连续set 
Dialog dialog = new AlertDialog.Builder(MyDialogDemo.this)
.setTitle("ȷ��ɾ��") // ��������
.setMessage("��ȷ��Ҫɾ�������Ϣ��") // ��ʾ�Ի����е�����
.setIcon(R.drawable.pic_m) // ����LOGO
.setPositiveButton("ɾ��", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
}).setNeutralButton("�鿴����", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
}).setNegativeButton("ȡ��", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
}).create(); // ������һ��Ի-------------------------------------------------

解决方案 »

  1.   

    Java中的链式方法调用,第一个方法调用返回的是该方法的对象引用,因而这个引用可以产生下一个方法调用,从而生成一个调用链。
      

  2.   


      public class Student{
        String name;
        boolean sex;
        public Student setName(String name){
          this.name = name;
          return this;
        }
        public Student setSex(boolean sex){
          this.sex = sex;
          return this;
        }
        public static void main(String args[]){
          Student s = new Student();
          s.setName("name").setSex(true);    
        }
      }
    懂没?