This feels like a dumb question and could even be a duplicate (I've looked, but can't find it).
But how in the heck (if it is even possible) do I do this with type safety?
ArrayList<String> myList = applicationContext.getBean( ArrayList<String>.class );
Java implements generics via type erasure. Which means the generic type is available at compile time but is Object at runtime. So no, there's no way to get that to work without casting.
Sadly, you don't. That would require knowledge at runtime about the parameterized type <String>
, and only the compiler knows that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With