1、以com.ecwid.consul.v1.QueryParams类举例,先建立QueryParams类,其中定义一些全局变量,声明一个含参的构造器:
public final class QueryParams implements UrlParameters {
public static final QueryParams DEFAULT;
private final String datacenter;
private final ConsistencyMode consistencyMode;
private final long waitTime;
private final long index;
private final String near;
private QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index, String near) {
this.datacenter = datacenter;
this.consistencyMode = consistencyMode;
this.waitTime = waitTime;
this.index = index;
this.near = near;
}
}
2、在QueryParams类中定义一个静态内部类Builder,Builder中定义一些全局变量,和它的外部类QueryParams保持一致。
public static final class Builder {
private String datacenter = null;
private