get Class Package - Java Reflection

Java examples for Reflection:Class

Description

get Class Package

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        Class classInstance = String.class;
        System.out.println(getClassPackage(classInstance));
    }//  www .  jav  a 2s.c om

    public static Package getClassPackage(Class<?> classInstance) {

        Package p;
        p = classInstance.getPackage();

        if (p != null)
            return p;
        else {
            return null;
        }

    }
}

Related Tutorials