On Sun, 24 Feb 2008 19:30:16 -0800, prowyh
> Thanks for all of your responses. I'm frustrated that it is impossible
> to create an instance of type T due to the type erasure of Java.
I don't understand why you wrote that. You got at least two suggestions
for how to accomplish this. I agree with Daniel that you should avoid
reflection if you can, but based on your description is seems that you
need this to work in a general case where you can't ensure that your
generic type parameter implements a specific interface (per his example).
But even in that case, Joshua's suggestion should work just fine. The
code will throw an exception unless the type being used has a constructor
that takes a string, in which case it will return a new instance of the
type, just as you're asking for.
Was there something about Joshua's suggestion you didn't understand? Did
you try using the code he posted? Is there something specific about his
suggestion that doesn't work for you?
Pete