レベルエンター山本大のブログ

面白いプログラミング教育を若い人たちに

BLOCKVROCKリファレンス目次はこちら

[翻訳]Guice User's Guide ■23. Creating Scope Annotations

スコープアノテーションの作り方

Annotations used for scoping should:

範囲指定のために使うアノテーションは以下のように作成します。

  • Have a @Rentention(RUNTIME) annotation so we can see the annotation at runtime.
  • Have a @Target({TYPE}) annotation. Scope annotations only apply to implementation classes..
  • Have a @ScopeAnnotation meta-annotation. Only one such annotation can apply to a given class.

For example:

たとえば以下です。

/**
 * Scopes bindings to the current transaction.
 */
@Retention(RUNTIME)
@Target({TYPE})
@ScopeAnnotation
public @interface TransactionScoped {}