get Class Modifiers - Java Reflection

Java examples for Reflection:Modifier

Description

get Class Modifiers

Demo Code


//package com.java2s;

import java.lang.reflect.Modifier;

public class Main {
    public static void main(String[] argv) throws Exception {
        Class classInstance = String.class;
        getClassModifiers(classInstance);
    }//w  w  w. j  a  v  a 2s .  co  m

    public static void getClassModifiers(Class<?> classInstance) {

        int mod = classInstance.getModifiers();
        System.out.print(Modifier.toString(mod)); //modifier

        if (Modifier.isInterface(mod))
            System.out.print(" "); // "interface"?modifier
        else
            System.out.print(" class "); // "class"

        System.out.print(classInstance.getName()); //class

    }
}

Related Tutorials