??????Java???????????????
???????????? ???????[ 2015/4/2 11:44:55 ] ????????Java ???? ???
?????????????÷??????????????
????Context context = new Context();
????Runnable runnable = ...
????context.put( "key"?? runnable?? Runnable.class );
????// several computation cycles later...
????Runnable value = context.get( "key"?? Runnable.class );
????????????δ???????????????????????????????6?б?????????????down cast??????????????????????????????????????????????10?и?????????ClassCastException ???????
????Context context = new Context();
????Runnable runnable = ...
????context.put( "key"?? runnable?? Runnable.class );
????// several computation cycles later...
????Executor executor = ...
????context.put( "key"?? executor?? Executor.class );
????// even more computation cycles later...
????Runnable value = context.get( "key"?? Runnable.class ); // runtime problem
??????????????????
?????????Context#get?е????????????Ч?????????????????t??????Object??????????????unbonded parameters??????????????????????????????????Context#put ????????????????????????????????????
??????????????????
???????????Context ????????????????????????????????????????????????????????key?? ??????????????????????????????Bloch????????????????????????typesafe heterogenous container pattern?????????ɡ?
???????????????key?????class ???????key?????Class ????????????????????????????Context??????????????????????????????δ?????????????T??????????????Class ????????????????type token????
????public class Context {
????private final Map<Class<?>?? Object> values = new HashMap<>();
????public <T> void put( Class<T> key?? T value ) {
????values.put( key?? value );
????}
????public <T> T get( Class<T> key ) {
????return key.cast( values.get( key ) );
????}
????[...]
????}
???????????Context#get ???????????????????Ч?????????滻???????????????????????????context??
????Context context = new Context();
????Runnable runnable ...
????context.put( Runnable.class?? runnable );
????// several computation cycles later...
????Executor executor = ...
????context.put( Executor.class?? executor );
????// even more computation cycles later...
????Runnable value = context.get( Runnable.class );
??????ο???????????????????????????????????????????????????????????????????????????????
?????й??????????????????????????????й?????????????????????????????????й?????????????????
????Bloch??????????????????????“???????????????????????????????raw form?????class????????????????????”?????????????????????????Context#put????????????dynamic cast????
????public <T> void put( Class<T> key?? T value ) {
????values.put( key?? key.cast( value ) );
????}
????????????????????????????????廯??non-reifiable ?????????У?????Effective Java????25???????仰???????????Runnable ??Runnable[]????????????List<Runnable>??
???????????List<Runnable>??????class???????е????????????????????List.class ????????Bloch????????????????????????????????
???????????????????洢??????????????????????????????????????????????????????????????????μ??????????????????????????????????Key??????????????
????????????????????
???????????洢????????????????????????????????key???Context ??????key??????????????????????????????????????????????value objects?????????????String ???????????????key???????????????
????public class Key<T> {
????final String identifier;
????final Class<T> type;
????public Key( String identifier?? Class<T> type ) {
????this.identifier = identifier;
????this.type = type;
????}
????}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????