Class cls = java.lang.String.class;
Package pkg = cls.getPackage();
String name = pkg.getName();              // java.lang

// getPackage() returns null for a class in the unnamed package
cls = MyClass.class;
pkg = cls.getPackage();                   // null

// getPackage() returns null for a primitive type or array
pkg = int.class.getPackage();    // null
pkg = int[].class.getPackage();  // null

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.