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 the case that the following assignment compiles without warnings (without warnings about unchecked casts):

  Bar<?> bar = new RawBar();

So is it then a subtype? Or isn't it? It's all terribly inconsistent if you ask me. :-(

Regards,
Sebastiaan



-----Original Message-----
From: Sebastiaan van Erk [mailto:[EMAIL PROTECTED] Sent: Friday, June 06, 2008 11:31 AM
To: 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 of
anything))".
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 subtype of

Bar<?>

But:

   Foo<? extends Bar<?>> rawbar = new RawBar(); // DOES NOT WORK -
THIS
IS CAUSING ONE HALF OF ALL OUR HEADACHES

(correction:)
    Foo<? extends Bar<?>> rawbar = new Foo<RawBar>(); // DOES NOT WORK -

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 a subtype of Bar<?>, so I *really* *really* *REALLY* have no idea why
the
compiler chokes on this.

ISSUE 2: The class literal of a generic type returns a class of a raw type. Thus Foo.class return Class<Foo>. This is also really messed
up,
because:
Class<Foo> fc = Foo.class;

compiles, but generates a warning (reference to raw type). But if you type 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,
see
also
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#1
5.8.2).

So what the heck is the proper type for the class literal??? I
couldn't
find 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 "Foo of

(anything that extends (bar of anything))" really is the correct interpretation.

It's just that the interaction with raw types is completely *foobar* (pun intended).

Regards,
Sebastiaan








______________

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]

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to