Home Java Reflect Examine Interface Example



Examine Interface Example
Posted on: September 10, 2008 at 12:00 AM
In this part of tutorial we will discuss how do you know that whether a given class is an "Interface" or a "Class"?

Examine Interface Example

     

In this part of tutorial we will discuss how do you know that whether a given class is an "Interface" or a "Class"

To know that given class is an Interface or Class we can use  boolean method isInterface() which returns true if given class is an Interface and false if it is a class.

 

 

 

 

 

Here is the code for this example:

import java.lang.reflect.*;

public class ExamineInterface {
  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("Interface name is -->"
 
+ intfs[i].getName());
 if (intfs[i].isInterface()) {
 System.out.println(intfs[i].getName() 
  + 
" is an interface.");
 else {
 System.out.println(intfs[i].getName()
    
" is a class.");
  
  }
  }
}

Output:

Download Source Code

Related Tags for Examine Interface Example:
cclassinterfacetutorialintriathistoeilartceinnopartasntparaceclhowdotorsdiscatkishallivdiscussarrttutorssrithhatfaceo


More Tutorials from this section

Ask Questions?    Discuss: Examine Interface Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.