-
23 Feb 2012 1:02 AM #1
Unanswered: ValueProvider ugly cast
Unanswered: ValueProvider ugly cast
It is possible to avoid the ugly ValueProvider cast ? TreeStore ModelKeyProvider is ok but the other... :-(
http://pastebin.com/eri7Prkc
-
23 Feb 2012 8:42 AM #2
All the generics in 3.x do make things a little more tricky. Are you getting a compiler error or is your IDE complaining about the line if you don't have the cast?
-
23 Feb 2012 8:51 AM #3
Its just a compiler warning. The TreeStore constructor has <? super M> to allow supertypes for ModelKeyProvider but the Tree constructor does not allow the same for ValueProvider. I think that is the reason i have to put a ugly cast. Is it planned to refactor ValueProvider declarations to allow supertypes in the same way TreeStore and ListStore allow for ModelKeyProvider ?
Code:public TreeStore(ModelKeyProvider<? super M> keyProvider)
Code:public Tree(TreeStore<M> store, ValueProvider<M, C> valueProvider)
-
23 Feb 2012 9:24 AM #4
I assume the warning is about an unchecked cast?
I created a subclass of Tree that modified the constructor argument to ValueProvider<? super M, C> and everything is happy except for the call to super(...) which expects M and not a parent.
I agree this seems like an oversight considering TreeStore has the <? super M> signature but admit I don't know the ramifications of changing this.
As I do not work for Sencha I cannot speak to the refactoring of the ValueProvider parameter. I would suggest and encourage you to file a bug in the bug forum with a title of something like "Inconsistent constructor signature between TreeStore and Tree" and then go into detail with your example (and solution).
HTH.
--adam
-
28 Feb 2012 10:14 AM #5
Many places that accept ValueProvider<T,V> can usually accept ValueProvider<? super T, V> - I have a patch that changes this in many places, but I've had concerns about committing it for the sake of readability, and for actually testing each and every case to be sure it can cause no other issues. As this has an (admittedly ugly) work around, this is a cleanup issue that has been ignored while harder to work around issues are attended to.
If I may ask, how are you creating these that you want the superclass of the model? PropertyAccess types can be made generic as of beta3, letting you define subtypes that make that type concrete. This doesn't completely deal with the issue, but in many cases it can prevent those ugly casts.
-
9 Mar 2012 4:40 AM #6
Thx Collin. I'm having the same problems with ComboBox LabelProvider not accepting supertypes.
In the first post you have a link to the example code im having problems with.
-
28 Mar 2012 12:03 PM #7
Thanks for the feedback everyone, in the 3.0.0 RC (www.sencha.com/products/extgwt/download) we just put up for download, you should see generics changes to deal with these kinds of cases - nearly all cases where ValueProvider<M,V>, or LabelProvider<M> is accepted, we've changed it to ValueProvider<? super M, V> and LabelProvider<? super M>. This hurt readability slightly, but makes it flexible to accept any kind of generated provider.
Please update this thread if you find cases I've missed or want to discuss other generics issues.
-
3 Apr 2012 7:56 AM #8
Many thanks Colin for commit this refactor. The application code now is more clean.



Reply With Quote