当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Package getPackages()用法及代码示例


java.lang.Package类的getPackages()方法用于获取由调用者的类加载器定义的Packages。该方法将软件包作为Package对象的数组返回。

用法:

public boolean getPackages(String desiredVersion)

参数:此方法不接受任何参数。


返回值:此方法将软件包作为Package对象的数组返回。

下面的程序演示了getPackages()方法。

范例1:

// Java program to demonstrate 
// getPackages() method 
  
public class Test { 
    public static void main(String[] args) 
    { 
  
        // get the Packages using getPackages() method 
        Package[] packages = Package.getPackages(); 
  
        // print all packages, one by one 
        for (int i = 0; i < packages.length; i++) { 
            System.out.println(packages[i]); 
        } 
    } 
}
输出:
package sun.reflect, Java Platform API Specification, version 1.8
package java.util, Java Platform API Specification, version 1.8
package sun.reflect.annotation, Java Platform API Specification, version 1.8
package java.lang.annotation, Java Platform API Specification, version 1.8
package java.nio, Java Platform API Specification, version 1.8
package sun.nio, Java Platform API Specification, version 1.8
package java.security.cert, Java Platform API Specification, version 1.8
package java.util.zip, Java Platform API Specification, version 1.8
package sun.launcher, Java Platform API Specification, version 1.8
package sun.security.action, Java Platform API Specification, version 1.8
package java.nio.file, Java Platform API Specification, version 1.8
package java.nio.charset, Java Platform API Specification, version 1.8
package sun.net.www, Java Platform API Specification, version 1.8
package java.lang.ref, Java Platform API Specification, version 1.8
package java.net, Java Platform API Specification, version 1.8
package sun.net.www.protocol.file, Java Platform API Specification, version 1.8
package java.lang.invoke, Java Platform API Specification, version 1.8
package sun.util.locale, Java Platform API Specification, version 1.8
package sun.reflect.generics.repository, Java Platform API Specification, version 1.8
package sun.misc, Java Platform API Specification, version 1.8
package java.lang.reflect, Java Platform API Specification, version 1.8
package sun.net.util, Java Platform API Specification, version 1.8
package java.security, Java Platform API Specification, version 1.8
package sun.net.www.protocol.jar, Java Platform API Specification, version 1.8
package java.util.concurrent, Java Platform API Specification, version 1.8
package java.util.concurrent.atomic, Java Platform API Specification, version 1.8
package java.util.concurrent.locks, Java Platform API Specification, version 1.8
package sun.util, Java Platform API Specification, version 1.8
package java.lang, Java Platform API Specification, version 1.8
package java.io, Java Platform API Specification, version 1.8
package sun.reflect.misc, Java Platform API Specification, version 1.8
package sun.nio.ch, Java Platform API Specification, version 1.8
package java.util.jar, Java Platform API Specification, version 1.8
package sun.nio.cs, Java Platform API Specification, version 1.8
package java.util.function, Java Platform API Specification, version 1.8
package java.nio.charset.spi, Java Platform API Specification, version 1.8
package sun.security.util, Java Platform API Specification, version 1.8

参考: https://docs.oracle.com/javase/9/docs/api/java/lang/Package.html#getPackages-



相关用法


注:本文由纯净天空筛选整理自guptayashgupta53大神的英文原创作品 Package getPackages() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。