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


public Class<HomePage> getHomePage(){
        return HomePage.class;
}

The first one has an annotation Override. What does that mean or what does it send to the framework.

Will both the methods return the same class. I mean what does this mean ? extends Page. I mean the ? Mark.

Bert F
  • 85,407
  • 12
  • 106
  • 123
theJava
  • 14,620
  • 45
  • 131
  • 172

4 Answers4

2

JavaDoc

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
2

@Override

the @Override annotation informs the compiler that the element is meant to override an element declared in a superclass (overriding methods will be discussed in the the lesson titled "Interfaces and Inheritance").

Also See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • 1
    Expanding on this a bit, it'll give you a neat underlined error in IDE's indicating you're not actually overriding (or implementing) a method in a superclass or interface. This'll help with, for example, typos (writing a method 'getHomPage()', which wouldn't give any error messages, just odd behavior as it seems your own getHomePage() method won't get executed). – cthulhu Dec 20 '10 at 12:21
  • @Cthulhu IDE gets this info from compiler only, and use this is true usage of `@Override` , check updated answer – jmj Dec 20 '10 at 12:22
2

And to the second question: a wildcard.

Both methods will return the same object (the Class instance representing HomePage), but they are declared in different ways, allowing the wild-carded version to be used by methods that don't care what kind of Page you have, as long as it's a subclass of Page.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
1

1) Override Annotation

Javadoc : Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.

2) ? means any. for example : < ? > means any java data type can be here

< ? extends Page > means any subclass of Page is allowed here.