Zappaterrini, Larry wrote:
Sebastiaan,Point 1 is a good one. I haven't puzzled that through completely. Upon initial inspection it seems that it is just the compiler being pedantic about a scenario that wouldn't arise in practice. I'll have to think about it some more. I might be missing something with point 2, but what is wrong with Class<Foo> clazz = Foo.class?
If Foo is a generic type (as in the example I gave), then the above assignment will give you a warning (which I don't know how to get rid off without a suppress)...
Foo is a raw type. References to generic type Foo<T> should be parameterized Regards, Sebastiaan
Cheers, Larry -----Original Message-----From: Sebastiaan van Erk [mailto:[EMAIL PROTECTED] Sent: Saturday, June 07, 2008 3:57 AMTo: users@wicket.apache.org Subject: Re: (Class<? extends Page<?>>) casting troubles Zappaterrini, Larry wrote:Sorry, I should have been more clear about subtype. :) When dealingwithraw types, the raw type is considered a super type of the generictype.So Bar is a super type of Bar<?>. Since RawType extends the raw type Bar, consider it to be a peer of Bar<?>. When you consider them as peers, a warning is warranted. The new example you use works due to erasure. Bar<?> as declared in source code becomes Bar in byte code.Sothe statement becomes: Bar bar = new RawBar(); Which is perfectly legal. I have found that most of perceived inconsistencies in Java generics stems from erasure and sub type substitution. The golden rule of generics is that the byte codeproducedby compiling generics will never produce an invalid cast so long asthecode does not produce any warnings. This causes some things that may seem intuitive to be illegal.Thanks for your explanation. I still think it's all rather horrible though. Type erasure was a huge mistake if you ask me. Two questions foryou though...1) Can you come up with an example where assigning a Foo<? extends Bar> to a Foo<? extends Bar<?>> causes an invalid cast? (So I can understand why this intuitive seeming assignment is illegal).2) How do you get rid of the warning in Class<Foo> clazz = Foo.class without using Class<?>? Because it would seem strange if there is no warning free way to use a certain language construct...Regards, Sebastiaan-----Original Message-----From: Sebastiaan van Erk [mailto:[EMAIL PROTECTED] Sent: Friday, June 06, 2008 4:16 PMTo: users@wicket.apache.org Subject: Re: (Class<? extends Page<?>>) casting troubles Zappaterrini, Larry wrote:In the example you have detailed, RawBar is not a subtype of Bar<?> since it extends the raw type Bar.I guess it depends on the definition of subtype. It is at least thecasethat the following assignment compiles without warnings (without warnings about unchecked casts):ifBar<?> bar = new RawBar(); So is it then a subtype? Or isn't it? It's all terribly inconsistentyou ask me. :-( Regards, Sebastiaan-----Original Message-----From: Sebastiaan van Erk [mailto:[EMAIL PROTECTED] Sent: Friday, June 06, 2008 11:31 AMTo: users@wicket.apache.org Subject: Re: (Class<? extends Page<?>>) casting troubles ARgh, you always make typos with this stuff. See correction. Sebastiaan van Erk wrote:Martin Funk wrote:Class<? extends Page<?>> means "class of (anything that extends(page ofanything))".I'm not so sure.There are 2 separate issues:ISSUE 1: Foo<? extends Bar<?>> is not assignable from a Foo<RawBar> where RawBar extends Bar as a raw type. That is, given:static class Foo<T> { } static class Bar<T> { } static class RawBar extends Bar { } static class SubBar<T> extends Bar<T> { } Thus: Bar<?> bar = new RawBar(); // works, because RawBar is a subtypeofTHISBar<?> But: Foo<? extends Bar<?>> rawbar = new RawBar(); // DOES NOT WORK -IS CAUSING ONE HALF OF ALL OUR HEADACHES(correction:) Foo<? extends Bar<?>> rawbar = new Foo<RawBar>(); // DOES NOTWORK-THIS IS CAUSING ONE HALF OF ALL OUR HEADACHES Btw, this does work (like you expect): Foo<? extends Bar<?>> rawbar2 = new Foo<SubBar<?>>();Note that this is the issue that complete baffles me, as RawBar is athesubtype of Bar<?>, so I *really* *really* *REALLY* have no idea whycompiler chokes on this. ISSUE 2: The class literal of a generic type returns a class of arawup,type. Thus Foo.class return Class<Foo>. This is also really messedbecause:Class<Foo> fc = Foo.class;compiles, but generates a warning (reference to raw type). But ifyouseetype this in eclipse: x fc = Foo.class;and use eclipse quickfix to change "x" to the "correct" type, it'll change it to precisely Class<Foo> (the JLS is very short about this,alsohttp://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.8.2).couldn'tSo what the heck is the proper type for the class literal??? Ifind any! Finally, note that when you define a method like this: static void method1(Foo<? extends Bar<?>> y) { } it works like a charm for a new Foo<SubBar<String>>, i.e., the "Fooof(anything that extends (bar of anything))" really is the correct interpretation.It's just that the interaction with raw types is completely *foobar*confidential. If you are not the(pun intended). Regards, Sebastiaan______________ The information contained in this message is proprietary and/or(ii) do not disclose,intended recipient, please: (i) delete the message and all copies;sender immediately. In addition,distribute or use the message in any manner; and (iii) notify theplease be aware that any message addressed to our domain is subjecttoarchiving and review byconfidential. If you are not thepersons other than the intended recipient. Thank you. _____________ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]______________ The information contained in this message is proprietary and/or(ii) do not disclose,intended recipient, please: (i) delete the message and all copies;sender immediately. In addition,distribute or use the message in any manner; and (iii) notify thearchiving and review byplease be aware that any message addressed to our domain is subject topersons other than the intended recipient. Thank you. _____________ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]______________The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you._____________ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
smime.p7s
Description: S/MIME Cryptographic Signature