Saturday 16 August 2014

getInterfaces() : Interfaces implemented by this class

You can get the interfaces implemented by this class using getInterfaces() method of java.lang.Class.

import java.util.*;

public class GetImplementedInterfaces {
    public static void main(String args[]){
        HashSet<Integer> mySet = new HashSet<>();
        
        Class[] interfaces = mySet.getClass().getInterfaces();
        
        System.out.println("Interfaces implemented by HashSet are");
        for(Class c : interfaces)
            System.out.println(c.getName());
    }
}

Output
Interfaces implemented by HashSet are
java.util.Set
java.lang.Cloneable
java.io.Serializable


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment