한 번에 끝내는 Java/Spring 웹 개발 마스터
- Generic
package ch06;
public class Powder {
public String toString() {
return "재료는 파우더 입니다.";
}
}
package ch06;
public class GenericPrinter<T> {
private T material;
public T getMaterial() {
return material;
}
public void setMaterial(T material) {
this.material = material;
}
public String toString() {
return material.toString();
}
}
package ch06;
public class GenericPrinterTest {
public static void main(String[] args) {
Powder powder = new Powder();
GenericPrinter<Powder> powderPrinter = new GenericPrinter<>();
powderPrinter.setMaterial(powder);
Powder p = powderPrinter.getMaterial();
System.out.println(powderPrinter.toString());
}
}
제네릭 (Generic) 프로그래밍