Java Package getPackage()方法与示例
包類的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 methodpublic class GetPackage {public static void main(String[] args) {// Get Package by using getPackage() methodPackage pkg = Package.getPackage("java.util");// Get name of the package and//stored in a variable pnameString pname = pkg.getName();// Display name of the packageSystem.out.print("Package Name: ");System.out.print(pname);} }Output
輸出量
Package Name: java.util翻譯自: https://www.includehelp.com/java/package-getpackage-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java Package getPackage()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: strspn函数php,php strs
- 下一篇: 互联网传真 传真指令_传真的完整形式是什