Arguments Against Annotations

前端 未结 12 1820
北海茫月
北海茫月 2020-12-23 13:48

My team is moving to Spring 3.0 and there are some people who want to start moving everything into Annotations. I just get a really bad feeling in my gut (code smell?) when

12条回答
  •  一个人的身影
    2020-12-23 13:58

    Maybe you have a problem with redundant annotations that are all over the code. With meta-annotations redundant annotations can be replaced and your annotations are at least DRY.

    From the Spring Blog:

    @Service
    @Scope("request")
    @Transactional(rollbackFor=Exception.class)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface MyService {
    }
    
    @MyService
    public class RewardsService {
    …
    }
    

    Because Java evolves so slowly people are putting more features that are missing in the language into annotations. This is a good thing Java can be extended in some form and this is a bad thing as most of the annotations are some workaround and add complexity.

提交回复
热议问题