Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Item<I extends Item<I>> {
- public abstract void add();
- public abstract void test();
- public static <T extends Item<T>> Item<T> getZero() {
- return T.ZERO();
- }
- protected static <T extends Item<T>> Item<T> ZERO() {
- class ZERO extends Item<T> {
- public void add() {}
- public void test() { System.out.println("item"); } // don't call this
- }
- return new ZERO();
- }
- public static void main(String[] args) {
- Item.<Book>getZero().test();
- }
- }
- class Book extends Item<Book> {
- public void add() { /* addition implementation goes here */ }
- public void test() { System.out.println("book"); } // this should be called
- protected static Item<Book> ZERO() { return new Book(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement