提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取包和类名
/** 时代Java 提供 **/ //package com.nowjava; public class Main { public static void main(String[] argv) { Class cls = String.class; System.out.println(getPackageAndClassName(cls)); } public static String getPackageAndClassName(Class<?> cls) { if (cls != null) { StringBuilder builder = new StringBuilder(); builder.append(cls.getPackage().getName()); builder.append("."); builder.append(c