Martin Funk wrote:
Jeremy Thomerson wrote:
I haven't read the whole thread, but you should be fine as long as your
returned page class uses generics...

Here's what I use in one app, no warnings, no casts:

    @Override
    public Class<? extends Page<?>> getHomePage() {
        return Home.class;
    }


public class Home extends WebPage<Void> {
}

Hi Jeremy,

I'm still picking on the words. What do you mean by 'uses generics'?

I think the point is class Home has to be a non generic type subclassing the generic class WebPage with a concrete type parameter.

Why should the HomePage class be "non generic", and why should you use a "concrete type parameter"?

Class<? extends Page<?>> means "class of (anything that extends (page of anything))".

That means your home page can have as many type parameters as you wish (or none at all), as long as it extends Page<?>. This also means you you can define a generic HomePage like this:

class HomePage<T> extends WebPage<T> { ... }

if you feel like it, and don't have to use a concrete type.

And I still really don't understand why java has a problem with this:

class HomePage extends WebPage { ... }

since here it *is still* the case that HomePage is a subtype of WebPage<?> (you prove this by the assignment:

WebPage<?> wp = new HomePage();

which works fine). So you would expect to be able to return this in the getHomePage() method. But you can't because the compiler chokes on it. I have not seen a convincing reason why this shouldn't work yet, though.

Regards,
Sebastiaan

mf

---------------------------------------------------------------------
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