日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java类class forName()方法及示例

發布時間:2023/12/1 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java类class forName()方法及示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

類類forName()方法 (Class class forName() method)

  • forName() method is available in java.lang package.

    forName()方法在java.lang包中可用。

  • forName() method is used to return the class object for the Class with the given class_name.

    forName()方法用于返回具有給定class_name的Class的類對象。

  • forName() 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 any error.

    forName()方法是一個靜態方法,可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,則不會出現任何錯誤。

  • forName() method may throw an exception at the time of returning a Class object.

    forName()方法在返回Class對象時可能會引發異常。

    • LinkageError: This exception may throw when we get linking error.LinkageError :當我們獲得鏈接錯誤時,可能會拋出此異常。
    • ExceptionInInitializeError: In this exception when the initialization is done by this method fails.ExceptionInInitializeError :在此方法中,初始化失敗的此異常。
    • ClassNotFoundException: In this exception when the given class does not exist.ClassNotFoundException :如果給定的類不存在,則在此異常中。

Syntax:

句法:

public static Class forName(String class_name);

Parameter(s):

參數:

  • String class_name – represents the fully qualified name of the given class.

    字符串class_name –代表給定類的完全限定名稱。

Return value:

返回值:

The return type of this method is Class, it returns this Class object for the class with the given name.

該方法的返回類型為Class ,它將為具有給定名稱的類返回此Class對象。

Example:

例:

// Java program to demonstrate the example // of Class forName (String class_name) method of Class public class ForNameOfClass {public static void main(String[] args) throws Exception {// It returns the Class 'java.lang.Object' object for the class // with the given class nameClass cl = Class.forName("java.lang.Object");// Display Name, Package and InterfacesSystem.out.print("Class 'java.lang.Object' Name: ");System.out.println(cl.getName());System.out.print("Class 'java.lang.Object' Package: ");System.out.println(cl.getPackage());System.out.print("Class 'java.lang.Object' Interface: ");System.out.println(cl.getInterfaces());} }

Output

輸出量

Class 'java.lang.Object' Name: java.lang.Object Class 'java.lang.Object' Package: package java.lang Class 'java.lang.Object' Interface: [Ljava.lang.Class;@68f7aae2

翻譯自: https://www.includehelp.com/java/class-class-forname-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java类class forName()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。