public class Computer {
private String os;
public Computer(String os) {
this.os = os;
}
}
public class Main {
public static void main(String[] args) {
Computer appleCom = new Computer("mac");
Computer windowCom = new Computer("window");
}
}
public class Computer {
private String os;
private Computer(String os) {
this.os = os;
}
public static Computer WindowComputer() {
return new Computer("window");
}
public static Computer AppleComputer() {
return new Computer("mac");
}
}
public class Main {
public static void main(String[] args) {
Computer.AppleComputer();
Computer.WindowComputer();
}
}
.
// public 생성자
Computer(String, int, int)
// 정적 팩토리 메소드
Computer.appleComputer()
public static Boolean valueOf(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}
public class Computer {
private static Map<String, Computer> computerMap = new HashMap<>();
private String OS;
public Computer(String OS) {
this.OS = OS;
}
static {
computerMap.put("APPLE", new Computer("MAC"));
computerMap.put("MICROSOFT", new Computer("WINDOW"));
computerMap.put("SAMSUNG", new Computer("TIZEN"));
}
public static Computer valueOf(String name) {
if(computerMap.containsKey(name)) {
return computerMap.get(name);
}
return new Computer(name);
}
}
class Singleton {
private Singleton(){};
private static final Singleton INSTANCE = new Singleton();
public Singleton getInstance() {
return INSTANCE;
}
}
class Instantiae {
private Instantiae(){};
public Singleton getInstance() {
return new Instantiae();
}
}
public static Boolean valueOf(boolean b) {
return b ? Boolean.TRUE : Boolean.FALSE;
}
public enum Enumeration {
FIRST, SECOND, THIRD ;
}
class Main {
public static void main(String[] args) {
Enumeration test1 = Enumeration.FIRST;
Enumeration test2 = Enumeration.SECOND;
Enumeration test3 = Enumeration.FIRST;
System.out.println(test1 == test2); // false
System.out.println(test1 == test3); // true
}
}
public class Computer implements ComputerInterface{}
public interface ComputerInterface {
public static Computer getComputer() {
return new Computer();
}
}
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
Enum<?>[] universe = getUniverse(elementType);
if (universe == null)
throw new ClassCastException(elementType + " not an enum");
if (universe.length <= 64)
return new RegularEnumSet<>(elementType, universe);
else
return new JumboEnumSet<>(elementType, universe);
}
<제공>
<서비스>
와 정말 정리가 잘 되어있네요 🎉👍
처음에 PUBLIC 생성자, 정적 팩토리 메소드 코드만 나와 있는 부분에도 약간의 설명이 있으면 좋을거 같아요 😎