はgenerics hereジェネリック型クラスのdefition
の素敵な議論があります。しかし、彼らはすべてのクラスは、ジェネリック型の変数を受け入れることができる方法について話しています。私の質問は、ジェネリック型のクラス定義です。
クラスは今、私は戻り値の型がT
であることを理解し
protected final <T> T getBeanFromSpringContext(String name, Class<T> requiredType) {
if(springApplicationContext != null) {
return springApplicationContext.getBean(name, requiredType);
} else {
return null;
}
}
として定義されます。しかし、その後<T>
は、このClassオブジェクトによってモデル化されたクラスの型です。これは私がタイプを知らないので、なぜ<?>
ではないのですか?
戻り値の型はT
です。上記のように、このクラスはnull
を返すことができますか?
ところで、私はこのシングルラインのスタイルを好みますか? null:springApplicationContext.getBean(name、requiredType); ' – Bohemian