Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<pre lang="java"><pre lang="java">
I know that we cannot create an object of an interface .
Annotation e = new Annotation () ; // compile time error .

But I am confused about what happens in the following code .

Class c = ob.getClass() ; // ob is an object of a class created by us .

Annotation a[] = c.getAnnotations[] ;

// this returns an array of Annotation type but this is not an object of Annotation .

System.out.println ( a[0].hashCode() ) ; // or toString() method .

Which hashCode() method will run here ? I think it is not of class Object and can't be of the Annotation interface since Annotation's methods are abstract .
Is this method of a class which implements Annotation interface . But we haven't specified that class and there are many classes which implement Annotation interface .

Please someone explain this . I would be able to understand this if you provide in-depth explanation .Thanks .

What I have tried:

I tried to understand this through the documentation but got confused .
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900