我的第一个标题
构造者(Builder)模式
public class Demo{
private String name;
private String email;
private Demo(){
}
@Override
public String toString() {
return "Demo{" +
"name='" + name + '\'' +
", age=" + age +
", email='" + email + '\'' +
", address='" + address + '\'' +
'}'
public static class Builder{
private String name;
private String email;
public Builder(){
}
public Builder setName(String name){
this.name = name;
return this;
}
public Builder setEmail(String email){
this.email =email;
return this;
}
public Demo build(){
Demo demo = new Demo();
demo.name = name;
demo.age =age;
demo.email = email;
demo.address = address;
return demo;
}
}
public static void main(String[] args){
Builder builder = new Builder();
Builder builder1 = builder.setName("王富塘").setEmail("12313");
Demo build = builder.build();
System.out.println(build.toString());
}
}
}
这是第一个下的第一个
public static String getJson(String path){
URL url = new URL(path);
HttpConnection connection = (HttpConnection)url.HttpConnection();
}
public class User {
private static User user = new User();
private User(){
};
public static User getUser(){
return user;
}
}
public class Main{
User user = User.getUser();
User user1 = User.getUser();
if(user == user1){
System.out.println("相同");
}
}