Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. public void addProduct(T t) {
  2. if (t.getClass().isInstance(ComputerPart.class)) {
  3. products.add(t);
  4. }
  5. if (t.getClass().isInstance(Service.class)) {
  6. products.add(t);
  7. }
  8. if (t.getClass().isInstance(Peripheral.class)) {
  9. products.add(t);
  10. }
  11. else System.out.println("Not the right type of object.");
  12. }
  13.  
  14. ComputerPart c;
  15. c = new ComputerPart(12);
  16.  
  17. ComputerOrder<Product> g3 = new ComputerOrder<>();
  18. g3.addProduct(c);
  19. g3.print();
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement