When I try to compile I get recompile with -Xlint unchecked for details. When I run it says: "T extends Product declared in class GenericOrder.
I thought "T" meant I could shove any product in my array. My array also does not give an orderID. I like to check things before moving forward but I can't figure out how to create a GenericOrder with some computer parts.
abstract class Product {
protected float price;
// return the price of a particular product
abstract float price();
}
class ComputerPart extends Product {
public ComputerPart(float p) {
price = p;
}
@Override
public float price() {
return price;
}
}
class GenericOrder<T> {
private static int ID = 0;
private String orderID;
List<T> order;
public GenericOrder() {
orderID = "order ID " + ID++;
order = new ArrayList<>();
}
public String getOrderID() {
return orderID;
}
public void addToOrder(T newProduct) {
order.add(newProduct);
}
public List<T> getProducts() {
return order;
}
public static void main(String args[]) {
GenericOrder order = new GenericOrder ();
order.getOrderID();
order.addToOrder(new ComputerPart(5));
order.getProducts();
}
}