package Name from Class - Android java.lang.reflect

Android examples for java.lang.reflect:Package

Description

package Name from Class

Demo Code


//package com.java2s;
import android.support.annotation.NonNull;

public class Main {
    public static String packageName(@NonNull final Class cls) {
        return canonicalName(cls).replaceFirst("\\.[^\\.]+$", "");
    }/*w  ww .j  ava2 s.  c om*/

    public static String canonicalName(@NonNull final Class cls) {
        return cls.getCanonicalName();
    }
}

Related Tutorials