I have a method which returns a List
.
プロパティは、1つの汎用パラメータを持つ型です。
public class Property> { ... }
混合型のプロパティのリストを持っているので、特定の要素にどの型パラメータがあるのかわかりません。
私はそのようなことをしたいと思います:
List list = getList();
for(Property<?> crt : list)
{
PropertyWrapper<?> crtWrapper = new PropertyWrapper(crt.getGenericType());
// I know this doesn't exist ----^
}
ある文章では、現在の Property
と同じ汎用テンプレート引数を持つために PropertyWrapper
が必要です。これを行う方法はありますかですか?
I could apply a suggestion as stated in https://stackoverflow.com/a/3437930/146003 but even if I do this, how to instanciate the appropriate PropertyWrapper
then, only having an instance of Class
?
I can modify Property<?>
if required. I also don't mind if reflection needs to be used (I assume it needs to be)
EDIT: I forgot something. In fact I cannot instanciate the wrapper by the line
PropertyWrapper<?> crtWrapper = new PropertyWrapper(crt.getGenericType());
特殊なサブクラス( PropertyWrapper_String
)があるためです。
今私は2つの可能性を見ています:
1:文字列でクラスをインスタンス化する:
String strGenericType = "";
Class<?> wrapperClass = Class.forName("PropertyWrapper_" + strGenericType);
2:サブクラスを作成せずに汎用クラスを特殊化する方法はありますか?
あなたのヒントの前に多くのおかげで