// Computer
package ch02_generic;
public class Computer {
private String name;
public Computer(String name) {
this.name = name;
}
public String getString() {
return name;
}
public String toString() {
return "종류 : " + name;
}
}
--------------------------------------------------------------------------------
// Product
package ch02_generic;
public class Product<K, M> {
private K kind;
private M model;
public Product() {}
public Product(K kind, M model) {
this.kind = kind;
this.model = model;
}
public K getkind() {return kind;}
public void setkind(K kind) {this.kind = kind; }
public M getmodel() {return model;}
public void setmodel(M model) {this.model = model;}
public String toString() {
return kind + " - " + model;
}
}
package ch02_generic;
public class ProductTest {
public static void main(String[] args) {
Product<String, String> proA = new Product<>();
proA.setkind("음료");
proA.setmodel("코카콜라");
System.out.println(proA);
System.out.println();
Product<Computer, String> proB = new Product<>(new Computer("노트북"), "LG gram");
System.out.println(proB);
}
}