実際のクラスにJavaオブジェクト/文字列を変換:私は経由してJavaクラスのリストを取得
List<String> cF = classFinder.findClassesInPackage("com.some.test", Info.class);
classFinder
は、サービス/クラスであり、
findClassesInPackage
方法がで
@Info
注釈を持つパッケージ
com.some.test
内のすべてのクラスを見つけ
それら。 Info.class
はインターフェイス以外の2番目のパラメータです。
マイリストcF
は現在、以下の内容で満たされている:
Set<String> set = new HashSet<String>(cF);
目的:今
[com.some.test.example.FollTest, com.some.test.example.SubsTest, ..]
、私は経由して、重複するメソッドを削除するにはList cF
Set
にこれを変換する
私はしたいiterate
がこのセットにあるので、すべてclasses one-by-one
を取得し、最終的に各クラスのすべてのInfo
注釈を取得して印刷することができます。私は後でこれらの注釈を解析するので、これが必要です。
私の懸念:設定された要素は現在ストリングになっています。実際のクラスに変換するにはどうすればいいですか? - まだオブジェクト/文字列ではなく、私が欲しい実際のクラス
Object check = set.toArray()[0];
:ここ(For example: out of my first element in set: com.some.test.example.FollTest, I just want FollTest that too in class form)
は、私が最初に単一の要素のために何しようとしているものです。
そして、(例えば)注釈を読み取るための
:for (Annotation annotation : ClassName.class.getAnnotations()) {
Class<? extends Annotation> type = annotation.annotationType();
System.out.println("Values of " + type.getName());
for (Method method : type.getDeclaredMethods()) {
Object value = method.invoke(annotation, (Object[])null);
System.out.println(" " + method.getName() + ": " + value);
}
}
How do I get above ClassName? (although I have them in the String/Object form as part of list/set).
更新質問:私は、その内部のすべての注釈を取得し、私はクラス名を見つけたら、また、どのように行いますクラスを作り、それらを印刷しますか?
これを参照してください:http://www.java2s.com/Code/Java/Reflection/Getannotationbyannotationclass.htm私は特定のクラスの注釈をどのように取得できますか。
私は質問を更新しました。 –