tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Lang3 > Classes > Get All Interfaces

Get All Interfaces 

Apache Commons Lang 3.0 is a java library with lot of utilities and reusable components. This requires the library commons-lang3-3.0.1.jar to be in classpath. The following example shows using ClassUtils.getAllInterfaces() API. It returns the list of all interfaces implemented by the given class and its super classes.

File Name  :  
com/bethecoder/tutorials/commons_lang/tests/classes/GetInterfacesTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_lang.tests.classes;

import java.util.Hashtable;
import java.util.List;
import java.util.TreeSet;
import java.util.Vector;

import org.apache.commons.lang3.ClassUtils;

public class GetInterfacesTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    List<Class<?>> superClasses = ClassUtils.getAllInterfaces(Vector.class);
    System.out.println(superClasses);
    
    superClasses = ClassUtils.getAllInterfaces(Hashtable.class);
    System.out.println(superClasses);

    superClasses = ClassUtils.getAllInterfaces(TreeSet.class);
    System.out.println(superClasses);

  }
}
   

It gives the following output,
[interface java.util.List, interface java.util.Collection, 
	interface java.lang.Iterable, interface java.util.RandomAccess, 
	interface java.lang.Cloneable, interface java.io.Serializable]

[interface java.util.Map, interface java.lang.Cloneable, 
	interface java.io.Serializable]

[interface java.util.NavigableSet, interface java.util.SortedSet, 
	interface java.util.Set, interface java.util.Collection, 
	interface java.lang.Iterable, interface java.lang.Cloneable, 
	interface java.io.Serializable]



 
  


  
bl  br