Java半路出家——编程细节

Java半路出家——编程细节


* Interface中能够定义常量 *

public interface BeanFactory {
    String FACTORY_BEAN_PREFIX = "&";
    ...
}

如果你在阅读别人的代码过程中发现如上代码(来自spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java)。请不要惊讶,这里是合法的,并且jvm默认会为其加上final的修饰。

在编写framework接口方法的时候最好返回空列表或空数组,而不是null
理论依据:
微软Framework Design Guidelines->Guidelines for Collections
实战代码依据:

# by Rod Johnson
# org.springframework.beans.factory.support.DefaultListableBeanFactory
private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) {
        List<String> result = new ArrayList<String>();
                ...
}
# by Rod Johnson
# org.springframework.beans.factory.support.AbstractBeanFactory
public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport implements ConfigurableBeanFactory {

    ...
    /** Custom PropertyEditorRegistrars to apply to the beans of this factory */
    private final Set<PropertyEditorRegistrar> propertyEditorRegistrars =
            new LinkedHashSet<PropertyEditorRegistrar>(4);

    ...

    /** Custom PropertyEditors to apply to the beans of this factory */
    private final Map<Class<?>, Class<? extends PropertyEditor>> customEditors =
            new HashMap<Class<?>, Class<? extends PropertyEditor>>(4);

    /** String resolvers to apply e.g. to annotation attribute values */
    private final List<StringValueResolver> embeddedValueResolvers = new LinkedList<StringValueResolver>();

    /** BeanPostProcessors to apply in createBean */
    private final List<BeanPostProcessor> beanPostProcessors = new ArrayList<BeanPostProcessor>();
        ...
        /**
     * Return the list of BeanPostProcessors that will get applied
     * to beans created with this factory.
     */
    public List<BeanPostProcessor> getBeanPostProcessors() {
        return this.beanPostProcessors;
    }
        ...

参考

微软Framework Design Guidelines

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值