Howard Lewis Ship wrote:
There's an existing bug for this.  I'm not sure how fixable it's going
to be; welcome to the implementation nitty gritty of generic types and
type erasure.  Just cause you don't see the typecasts doesn't mean the
compiler has put them there.
Here's a challenge: what if there was a createWidget() method on your
class.  How would you implement it, to create an instance of the
correct class?  You can't do a new T() (the compiler won't let you,
since it doesn't know what T is).

As you say, the wonderful type erasure "feature" implies that you have to have more information about your type. For instance, you need to pass a "Class<T> type" to your create() method. Actually, it's not really an acceptable solution, but the sole workaround I know (if somebody as another idea, I would be glad to use it).

After that, you can use reflection :
8<-----------------------------
public class EditWidgetPage<T extends Widget> {
   T widget;
   T create(Class<T> type) {
       widget = type..newInstance();
      ....
}
}
8<-----------------------------

A bunch of infos are available at www.angelikalanger.com FAQs, and more precisely about your concern : http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#How%20do%20I%20pass%20type%20information%20to%20a%20method?


Hope it may help...


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to