Home Java Reflect Getting the implemented Interfaces
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Getting the implemented Interfaces

Advertisement
In this section you will learn how to retrieve an Interface (that included in the program) by using the getInterfaces() method. Here is an example that provides the usage of the getInterfaces() method in more detail.

Getting the implemented Interfaces

     

In this section you will learn how to retrieve an Interface (that included in the program) by using the getInterfaces() method. Here is an example that provides the usage of the getInterfaces() method in more detail.

Create an object of class Finterface and assign it with java.util.Integer.class.. Now retrieve Interfaces (included in the program) and store their references in an array of class Class by using the getInterfaces() method.

Here is the code of the Example :

Finterface.java:   

import java.lang.reflect.*;

public class Finterface {
  public static void main(String str[]){
  Class cls = java.util.List.class;
  Class[] intfs = cls.getInterfaces();
  int len = intfs.length;
  for (int i =0; i < len; i++)
  {
  System.out.println(intfs[i]);
  }

  }
}

Here is the output of this Example :

C:\roseindia>javac Finterface.java

C:\
roseindia>java Finterface
interface java.util.Collection

Download this Example:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Related Tutorials

Ask Questions?    Discuss: Getting the implemented Interfaces  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Gaurav Garg
August 19, 2013
About Interface getting

I am writing this code Class cls=java.lang.Integer.class; Class[] intfs = cls.getInterfaces(); int len = intfs.length; for(int i=0;i<len;i++) { System.out.println(intfs[i]+"\n"); } and output is coming interface java.lang.Comparable -------- but I want output only java.lang.Comparable
DMCA.com