Created
July 17, 2012 21:58
-
-
Save anton0xf/3132430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Registry<H extends Handler>{ | |
//абстрактный метод | |
void register(String s, H h); | |
//наш обобщенный код | |
void registerList(String s, List<H> hs){ | |
for(H h: hs) | |
register(s,h); | |
} | |
} | |
interface Handler{ | |
Object getHandler(); | |
} | |
class HttpRequestHandlerWrapper implements Handler{ | |
HttpRequestHandler handler; | |
HttpRequestHandlerWrapper(HttpRequestHandler handler){ | |
this.handler = handler; | |
} | |
//ковариантные возращаемые типы | |
public HttpRequestHandler getHandler(){ | |
return handler; | |
} | |
} | |
class HttpRequestHandlerRegistryWrapper extends Registry<HttpRequestHandlerWrapper>{ | |
HttpRequestHandlerRegistry reg; | |
void register(String s, HttpRequestHandlerWrapper h){ | |
reg.register(s, h.getHandler()); | |
// можно обойтись и без каста но немного сложнее | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment