包类的getPackage()方法 (Package Class getPackage() method)
- getPackage() method is available in java.lang package. - getPackage()方法在java.lang包中可用。 
- getPackage() method is used to search a package by given package name in the caller's ClassLoader instance when the callers ClassLoader instance exists null then the bundles of package loaded by that System ClassLoader instance is searched to determine the named package. - 当调用方的ClassLoader实例存在null时,将使用getPackage()方法在给定的调用方的ClassLoader实例中按给定的包名称搜索一个包,然后搜索该System ClassLoader实例加载的包的捆绑包以确定命名的包。 
- getPackage() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error. - getPackage()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。 
- getPackage() method does not throw an exception at the time of returning package. - getPackage()方法在返回包时不会引发异常。 
Syntax:
句法:
    public static Package getPackage(String pack_name);
Parameter(s):
参数:
- String pack_name – represents the fully qualified name of the package. - 字符串pack_name –表示软件包的标准名称。 
Return value:
返回值:
The return type of this method is Package, it returns the name of the given package else it returns null when no package exists from the database.
此方法的返回类型为Package ,它返回给定程序包的名称,否则,如果数据库中不存在任何程序包,则返回null。
Example:
例:
// Java program to demonstrate the example 
// of Package getPackage(String pack_name) 
// of Package method
public class GetPackage {
public static void main(String[] args) {
// Get Package by using getPackage() method
Package pkg = Package.getPackage("java.util");
// Get name of the package and
//stored in a variable pname
String pname = pkg.getName();
// Display name of the package
System.out.print("Package Name: ");
System.out.print(pname);
}
}
Output
输出量
Package Name: java.util
翻译自: https://www.includehelp.com/java/package-getpackage-method-with-example.aspx