描述
这个java.lang.Package.getPackages()方法获取调用者的 ClassLoader 实例当前已知的所有包。这些包对应于通过该 ClassLoader 实例的名称加载或可访问的类。如果调用者的ClassLoader实例是bootstrap ClassLoader实例,在某些实现中可能用null表示,则只返回bootstrap ClassLoader实例加载的类对应的包。
声明
以下是声明java.lang.Package.getPackages()方法
public static Package[] getPackages()
参数
NA
返回值
此方法返回调用者 ClassLoader 实例已知的包的新数组。如果不知道,则返回零长度数组。
异常
NA
示例
下面的例子展示了 lang.Object.getPackages() 方法的用法。
package com.tutorialspoint;
public class PackageDemo {
public static void main(String[] args) {
// get all the packages
Package[] pack = Package.getPackages();
// print all packages, one by one
for (int i = 0; i < pack.length; i++) {
System.out.println("" + pack[i]);
}
}
}
让我们编译并运行上面的程序,这将产生以下结果——
package sun.util, Java Platform API Specification, version 1.8 package java.util, Java Platform API Specification, version 1.8 package java.net, Java Platform API Specification, version 1.8 package sun.reflect.misc, Java Platform API Specification, version 1.8 package sun.security.provider, Java Platform API Specification, version 1.8 package sun.net.www.protocol.jar, Java Platform API Specification, version 1.8 package sun.security.action, Java Platform API Specification, version 1.8 package java.nio.charset, Java Platform API Specification, version 1.8 package sun.io, Java Platform API Specification, version 1.8 package java.io, Java Platform API Specification, version 1.8 package sun.nio, 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.lang, Java Platform API Specification, version 1.8 package sun.misc, Java Platform API Specification, version 1.8 package sun.net.www.protocol.file, 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 com.tutorialspoint package java.nio.charset.spi, Java Platform API Specification, version 1.8 package java.nio, Java Platform API Specification, version 1.8 package java.util.concurrent.locks, Java Platform API Specification, version 1.8 package sun.reflect, Java Platform API Specification, version 1.8 package java.security, Java Platform API Specification, version 1.8 package java.lang.reflect, Java Platform API Specification, version 1.8 package sun.nio.cs, Java Platform API Specification, version 1.8 package sun.security.util, Java Platform API Specification, version 1.8 package java.security.cert, Java Platform API Specification, version 1.8 package sun.jkernel, Java Platform API Specification, version 1.8 package sun.net.util, Java Platform API Specification, version 1.8
相关用法
- Java Java.lang.Package.getPackage()用法及代码示例
- Java Java.lang.Package.getSpecificationTitle()用法及代码示例
- Java Java.lang.Package.getAnnotations()用法及代码示例
- Java Java.lang.Package.getAnnotation()用法及代码示例
- Java Java.lang.Package.getName()用法及代码示例
- Java Java.lang.Package.toString()用法及代码示例
- Java Java.lang.Package.isSealed()用法及代码示例
- Java Java.lang.Package.isAnnotationPresent()用法及代码示例
- Java Java.lang.Package.hashCode()用法及代码示例
- Java Java.lang.Package.isCompatibleWith()用法及代码示例
- Java Java.lang.Process.getInputStream()用法及代码示例
- Java Java.lang.Process.getErrorStream()用法及代码示例
- Java Java.lang.Process.destroy()用法及代码示例
- Java Java.lang.ProcessBuilder.redirectErrorStream()用法及代码示例
- Java Java.lang.ProcessBuilder.directory()用法及代码示例
- Java Java.lang.ProcessBuilder.environment()用法及代码示例
- Java Java.lang.Process.exitValue()用法及代码示例
- Java Java.lang.Process.waitFor()用法及代码示例
- Java Java.lang.ProcessBuilder.redirectErrorStrestart()用法及代码示例
- Java Java.lang.Process.getOutputStream()用法及代码示例
注:本文由纯净天空筛选整理自 Java.lang.Package.getPackages() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。