Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. abstract class Item<I extends Item<I>> {
  2.  
  3. public abstract void add();
  4. public abstract void test();
  5.  
  6. public static <T extends Item<T>> Item<T> getZero() {
  7. return T.ZERO();
  8. }
  9.  
  10. protected static <T extends Item<T>> Item<T> ZERO() {
  11. class ZERO extends Item<T> {
  12. public void add() {}
  13. public void test() { System.out.println("item"); } // don't call this
  14. }
  15. return new ZERO();
  16. }
  17.  
  18. public static void main(String[] args) {
  19. Item.<Book>getZero().test();
  20. }
  21. }
  22.  
  23. class Book extends Item<Book> {
  24.  
  25. public void add() { /* addition implementation goes here */ }
  26. public void test() { System.out.println("book"); } // this should be called
  27.  
  28. protected static Item<Book> ZERO() { return new Book(); }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement