![Java apache commons AnnotationUtils サンプルプログラム](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons AnnotationUtils サンプルプログラム
AnnotationUtilsの説明(google翻訳)
Annotationインスタンスを操作するためのヘルパーメソッド。
このクラスには、アノテーションをより簡単に扱えるさまざまなユーティリティメソッドが含まれています。
アノテーションインスタンスは常にプロキシオブジェクトです。
残念ながら、動的なプロキシは、「自然な」アノテーションによって行われるのと同じ方法で特定のメソッドを実装する方法を知ることに依存することはできません。
このクラスで提示されたメソッドは、その可能性を避けるために使用できます。もちろん、動的プロキシが実際にそれらを委譲することも可能です。
Annotationにかかわる関数だと分かると思いますが、methodは4つのみ定義されています。
equals、hashCode、toString、isValidAnnotationMemberType
利用するのは、isValidAnnotationMemberTypeです。
メソッドの説明(google翻訳)
指定された型が注釈メンバとして許可されているかどうかを判定します。
Java言語仕様では、特定の型をアノテーションでのみ使用できます。これらには、文字列、クラス、プリミティブ型、注釈、列挙型、およびこれらの型の1次元配列が含まれます。パラメーター:
type – チェックする型、null
戻り値:
型がアノテーションで使用する有効な型である場合はtrue
AnnotationUtils#isValidAnnotationMemberType
DatabaseColoumn
package jp.pjin.tech.java.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; @Target(ElementType.FIELD) public @interface DatabaseColoumn { }
先にオリジナルのアノテーション(注釈)を作成します。
既存あるものを利用しても構いません。
CommonsExample2
package jp.pjin.tech.java; import jp.pjin.tech.java.annotation.DatabaseColoumn; import org.apache.commons.lang3.AnnotationUtils; public class CommonsExample2 { public static void main(String[] args) { System.out.println(AnnotationUtils .isValidAnnotationMemberType(DatabaseColoumn.class)); System.out.println(AnnotationUtils .isValidAnnotationMemberType(String.class)); System.out.println(AnnotationUtils.isValidAnnotationMemberType(null)); } }
Annotationのクラスかを判断するのに利用します。
注意点としては、ラッパークラスがtrueとString、列挙型がtrueになることです。
またnullはfalseが返ります。
注釈を新規で作成すれば「@interfase」が作成されます。
これを利用してリフレクションなどを行います。
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons StrSubstitutor サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons StrMatcher サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons StrLookup サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons StrBuilder サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons ExtendedMessageFormat サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons MethodUtils サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons InheritanceUtils サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons FieldUtils サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)
Java apache commons ConstructorUtils サンプルプログラム
![java apache commons](https://tech.pjin.jp/wp-content/uploads/2017/04/java.gif)