[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Anonymous beans
adrian@jboss.org
do-not-reply at jboss.com
Mon Apr 7 11:22:27 EDT 2008
"alesj" wrote :
|
| | public Object clone()
| | {
| | AbstractBeanMetaData clone = new AbstractBeanMetaData();
| | doClone(clone);
| | return clone;
| | }
| |
|
No you should use covariant return types
| public AbstractBeanMetaData clone()
| {
| ...
| }
|
anonymous wrote :
|
| | protected void doClone(AbstractBeanMetaData clone)
| | {
| | super.doClone(clone);
| | clone.setBean(bean);
| | clone.setName(name);
| | clone.setAliases(aliases);
| | ...
| | }
| |
|
Why are you "cloning" fields that are direct referenes? What does it achieve?
anonymous wrote :
| Do we already have some similar code, to clone collections:
|
| | @SuppressWarnings("unchecked")
| | public static <U extends JBossInterface, T extends Collection<U>> T clone(T collection)
| | {
| | if (collection == null)
| | return null;
| |
| | try
| | {
| | Class<? extends Collection> collectionClass = collection.getClass();
| | T clone = (T)collectionClass.newInstance();
| | for (U item : collection)
| | clone.add((U)item.clone());
| | return clone;
| | }
| | catch (Throwable t)
| | {
| | throw new RuntimeException(t);
| | }
| | }
| |
This looks overally complicated and an obvious misuse of generics again.
Why have generics then do all the casting and suppress warnings?
The way to clone collections is something like:
| Set<String> aliases = this.getAliases();
| if (aliases != null)
| clone.setAliases(new HashSet<String>(aliases));
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4142107#4142107
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4142107
More information about the jboss-dev-forums
mailing list