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 name
Class cl = Class.forName("java.lang.Object");
// Display Name, Package and Interfaces
System.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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378764.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378764.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378764.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

04-圖像的閾值操作

對圖像的閾值操作 import cv2 import matplotlib.pyplot as pltimg cv2.imread(E:/Jupyter_workspace/study/data/cat.png,1) ret, thresh1 cv2.threshold(img,127,255,cv2.THRESH_BINARY) ret, thresh2 cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV) ret, thresh3 c…

java虛擬機內存監控_深入理解JVM虛擬機9:JVM監控工具與診斷實踐

本文轉自:https://juejin.im/post/59e6c1f26fb9a0451c397a8c本系列文章將整理到我在GitHub上的《Java面試指南》倉庫,更多精彩內容請到我的倉庫里查看https://github.com/h3pl/Java-Tutorial喜歡的話麻煩點下Star哈文章將同步到我的個人博客:…

詳解:數據庫名、實例名、ORACLE_SID、數據庫域名、全局數據庫名、服務名

數據庫名、實例名、數據庫域名、全局數據庫名、服務名,這是幾個令很多初學者容易混淆的概念。相信很多初學者都與我一樣被標題上這些個概念搞得一頭霧水。我們現在就來把它們弄個明白。 一、數據庫名什么是數據庫名?數據庫名就是一個數據庫的標識&#…

顏色縮減 -利用指針、迭代器、動態地址實現訪問像素

為什么要使用顏色縮減 在對單通道圖像進行處理時,像素的可能值為256個,但處理多通道時,像素的處理就會相當麻煩,其實用這些顏色中具有代表性的一小部分就可以達到同樣的效果,所以顏色空間縮減就可以派上用場了。一個信…

setlenient_Java日歷setLenient()方法與示例

setlenient日歷類setLenient()方法 (Calendar Class setLenient() method) setLenient() method is available in java.util package. setLenient()方法在java.util包中可用。 setLenient() method is used to set or unset lenient status of date or time interpretations. s…

PowerShell_9_零基礎自學課程_9_高級主題:靜態類和類的操作

哈哈,昨天弄了個ubuntu 11.10在虛擬機上運行,發現11.10界面非常絢麗,但是其需要的系統資源非常多,我虛擬機設定內存為512M,1個CPU4個核心, 進入以后發現根本動不了,因此今天我就下載了一個Fedor…

05-圖像的平滑處理(不同的濾波操作)

對圖像進行平滑處理實則就是對圖像進行濾波操作罷了 每張圖片都有若干個像素點所構成,濾波操作上就是將照片上的某些部分像素點進行修改從而達到平滑的效果 先展示一下原圖 import cv2 img cv2.imread(E:\Jupyter_workspace\study\data/test1.png)cv2.imshow(te…

js刪除mysql記錄_(DELETEUPDATE)修改、刪除數據記錄_MySQL

有時,希望除去某些記錄或更改它們的內容。DELETE 和 UPDATE 語句令我們能做到這一點。用update修改記錄UPDATE tbl_name SET 要更改的列WHERE 要更新的記錄這里的 WHERE 子句是可選的,因此如果不指定的話,表中的每個記錄都被更新。例如&#…

C++設計模式之Abstract Factory模式

一、功能   提供一個創建一系列相關或相互依賴對象的接口,而無需指定它們具體的類。 二、結構圖類廠最基本的結構示意圖如下: 在實際應用中,類廠模式可以擴充到很復雜的情況,如下圖所示: 三、優缺點 優點&#xff1…

數字圖像處理小練習存檔1

小練習的題目: 1、讀取一張圖,分解RGB三個通道 /************練習1**********************/ int main() {Mat img1 imread("D:\\opencv_picture_test\\miku2.jpg",2|4); //灰度圖if (img1.empty()){printf("Could not find the imag…

UIImage 壓縮

1.改變圖片大小 -(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize {// Create a graphics image contextUIGraphicsBeginImageContext(newSize);// Tell the old image to draw in this new context, with the desired// new size[image drawInRect:CG…

06-對圖像進行腐蝕操作

形態學中的腐蝕操作一般處理的圖像數據為二值的 cv2.erode(img,kernel,iterations 1) kernel表示拿多大的卷積核去腐蝕 iterations表示迭代次數 可以將一些帶有毛毛的圖像去毛毛化 原圖 import cv2 import numpy as npdef show_photo(name,picture):cv2.imshow(name,picture)…

Java BufferedReader skip()方法與示例

BufferedReader類skip()方法 (BufferedReader Class skip() method) skip() method is available in java.io package. skip()方法在java.io包中可用。 skip() method is used to skip the given number of bytes of characters (n_bytes_of_char) from this BufferedReader. s…

mysql gtid binlog_MySQL之-四步實現BinLog Replication升級為GTIDs Replication的代碼實例

1、將Master和Slave服務器都設置為read-onlymysql>SET global.read_onlyON;2、將Master與Slave服務器都停下來service mysql stop3、開啟GTIDs開啟GTIDs需要在master和slave服務器上都配置gtid-mode,log-bin,log-slave-updates,enforce-gtid-consistency(在MySQL 5.6.9之前是…

【記】瑣碎

1.GIF載入問題:http://www.cnblogs.com/Lewis/archive/2011/01/17/1937066.html 2.正則分段數字: "12345678945612456".replace(new RegExp((\\d)(?(\\d{3})$),ig),"$1,") 其中用到了正則的后則判斷? 3.給legend設定寬度 發現IE下可以 火狐下…

spring對事務的控制 AOP

我解釋一下(* com.evan.crm.service.*.*(..))中幾個通配符的含義: |第一個 * —— 通配 任意返回值類型| |第二個 * —— 通配 包com.evan.crm.service下的任意class| |第三個 * —— 通配 包com.evan.crm.service下的任意class的任意方法| |第四個 .. —— 通配 方…

Opencv實現利用滑動條來調整閾值

#include <opencv2/opencv.hpp> #include <iostream>using namespace cv; using namespace std; #define WINDOW_NAME "【程序窗口】" //為窗口標題定義的宏 //*--------------------------【練習】利用滑動條來調整閾值-----------------------------…

07-對圖像進行膨脹操作

形態學中的膨脹操作即讓照片變得更大&#xff0c;與腐蝕操作互為逆運算 cv2.dilate(erosion,kernel,iterations 1) 第一個參數&#xff1a;圖像對象名稱 第二個參數&#xff1a;卷積核的大小 第三個參數&#xff1a;迭代次數 此時就可與腐蝕操作進行相結合&#xff0c;腐蝕去毛…

Java LocalDate類| parse()方法與示例

LocalDate類parse()方法 (LocalDate Class parse() method) Syntax: 句法&#xff1a; public static LocalDate parse(CharSequence c_seq);public static LocalDate parse(CharSequence c_seq, DateTimeFormatter fmtr);parse() method is available in java.time package. …

Xhtml學習筆記

1. XHTML 是什么&#xff1f; XHTML 指可擴展超文本標簽語言&#xff08;EXtensible HyperText Markup Language&#xff09;。 XHTML 的目標是取代 HTML。 XHTML 與 HTML 4.01 幾乎是相同的。 XHTML 是更嚴格更純凈的 HTML 版本。 XHTML 是作為一種 XML 應用被重新定義的 HTML…