Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

11.2.8.2. ステレオタイプの使用

概要

ステレオタイプを使用しないと、アノテーションが煩雑になる可能性があります。このタスクは、ステレオタイプを使用して煩雑さを軽減し、コードを効率化する方法を示しています。ステレオタイプとは何かについての詳細は、を参照してください。「ステレオタイプについて」

例11.14 注釈が乱雑

@Secure
@Transactional
@RequestScoped
@Named
public class AccountManager {
  public boolean transfer(Account a, Account b) {
    ...
  }
}

手順11.6 ステレオタイプの定義および使用

  1. ステレオタイプを定義します。

    @Secure
    @Transactional
    @RequestScoped
    @Named
    @Stereotype
    @Retention(RUNTIME)
    @Target(TYPE)
    public @interface BusinessComponent {
     ...
    }
    
  2. ステレオタイプを使用します。

    @BusinessComponent
    public class AccountManager {
      public boolean transfer(Account a, Account b) {
        ...
      }
    }
    

結果:

ステレオタイプは、コードを合理化および簡素化します。