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-
相關用法
- Java Package hashCode()用法及代碼示例
- Java Package getImplementationVersion()用法及代碼示例
- Java Package isSealed()用法及代碼示例
- Java Package isCompatibleWith()用法及代碼示例
- Java Package getSpecificationVendor()用法及代碼示例
- Java Package getName()用法及代碼示例
- Java Package getImplementationVendor()用法及代碼示例
- Java Package getSpecificationTitle()用法及代碼示例
- Java Package getSpecificationVersion()用法及代碼示例
- Java Package getImplementationTitle()用法及代碼示例
- Java Package getDeclaredAnnotationsByType()用法及代碼示例
- Java Package getAnnotation()用法及代碼示例
- Java Package isAnnotationPresent()用法及代碼示例
- Java Package isSealed(URL)用法及代碼示例
- Java Package getDeclaredAnnotations()用法及代碼示例
注:本文由純淨天空篩選整理自guptayashgupta53大神的英文原創作品 Package getPackages() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。