|
该帖已经被评为精华帖
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-05-13
引用 我的方案也差不多啦,IDE 里面 rename 一下,然后也只要改一处字符串就好。 这个,没懂啊。怎么能只改一处字符串的?假设有10个test case都依赖Foo。 |
|
| 返回顶楼 | |
|
时间:2008-05-21
不明白为什么需要这么处理,标准的简单问题复杂化
|
|
| 返回顶楼 | |
|
时间:2008-05-21
搞了一堆代码去代替原来很清晰的一堆代码,有意思吗?
|
|
| 返回顶楼 | |
|
时间:2008-06-10
@interface Foo {
int id(); String name() default ""; Gender sex(); } Map<String, String> map = ...; Foo foo = PropertyConverter.to(Foo.class).from(map); foo.id(); foo.name(); 没见过这种用法,学习 |
|
| 返回顶楼 | |
|
时间:2008-06-10
我觉得完全可以在这里问题上使用state模式,或者命令模式,或者使用aop来实现类型转换,那样楼主肯定觉得更优雅
|
|
| 返回顶楼 | |
|
时间:2008-06-10
感觉可以参考spring里面的类型转换吧,它好像用的是java的PropertyEditorSupport,感觉可以参考参考啊
|
|
| 返回顶楼 | |
|
时间:2008-06-16
呵呵,精益求精啊,不过有个地方参数顺序好像错了:
public final class PropertyConverter<T> {
private final Class<T> targetType;
private PropertyConverter(Class<T> targetType) {...}
public static <T> PropertyConverter<T> to(Class<T> targetType) {
return new PropertyConverter<T>(targetType);
}
public T from(final Map<String, String> map) {
return Proxy.newProxyInstance(
new Class[]{targetType}, targetType.getClassLoader(), new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) {
String value = map.get(method.getName());
if (value == null) {
Object defaultValue = method.getDefaultValue();
if (defaultValue == null) {
throw ...;
}
return defaultValue;
}
return convert(value, method.getReturnType());
}
});
}
}
11行,我看api里是下面这样的啊 newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) |
|
| 返回顶楼 | |
|
时间:2008-07-12
签名,泛型,代理
都是自己平时很少用到的,运行一下,学习一下 |
|
| 返回顶楼 | |
|
时间:2008-07-12
apache beanutils中
dwr中 jsf myfaces中 都有基本类型的转换实现。 自己反射下属性(beanutils也可以帮忙),加自动转换类型。 lz的东西就好了。 |
|
| 返回顶楼 | |
|
时间:2008-07-19
恩,不错,method.getReturnType 都用上了。动态代理的价值全被体现了
|
|
| 返回顶楼 | |








