Java ObjectStreamField toString()方法與示例

ObjectStreamField類toString()方法 (ObjectStreamField Class toString() method)

  • toString() method is available in java.io package.

    toString()方法在java.io包中可用。

  • toString() method is used to return a string that defines this field.

    toString()方法用于返回定義此字段的字符串。

  • toString() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    toString()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • toString() method does not throw an exception at the time of string representation.

    toString()方法在字符串表示時不會引發異常。

Syntax:

句法:

    public String toString();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is String, it returns string denotation of this ObjectStreamField.

方法的返回類型為String ,它返回此ObjectStreamField的字符串表示形式。

Example:

例:

// Java program to demonstrate the example 
// of String toString() method 
// of ObjectStreamField
import java.io.*;
import java.util.*;
public class ToStringOfOSF {
public static void main(String[] args) {
// Instantiates ObjectStreamClass for Calendar
ObjectStreamClass o_sc = ObjectStreamClass.lookup(Calendar.class);
// By using getField() method is to get the field
// value from Calendar 
ObjectStreamField field1 = o_sc.getField("isTimeSet");
ObjectStreamField field2 = o_sc.getField("fields");
// By using toString() method is used to
// represent the field as a string
String field1_str = field1.toString();
System.out.println("field1.toString(): " + field1_str);
String field2_str = field2.toString();
System.out.println("field2.toString(): " + field2_str);
}
}

Output

輸出量

field1.toString(): Z isTimeSet
field2.toString(): [I fields

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

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

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

相關文章

linux內核文件描述符fd、文件索引節點inode、文件對象file關系

文件描述符fd、文件索引節點inode、文件對象file關系1 VFS對象1.1 超級塊對象1.2 索引節點對象1.3 文件對象1.4 進程描述符1.5 files_struct2 如何根據文件描述符fd找到文件?1 VFS對象 在說fd、inode和file關系之前,我們先了解VFS的幾個概念。分別是進程…

sql2005 獲取表字段信息和視圖字段信息

獲取表字段名,和字段說明SELECT[Table Name]OBJECT_NAME(c.object_id), [ColumnName]c.name, [Description]ex.value FROMsys.columns c LEFTOUTERJOINsys.exte…

解析css之position

CSS的很多其他屬性大多容易理解,比如字體,文本,背景等。有些CSS書籍也會對這些簡單的屬性進行大張旗鼓的介紹,而偏偏忽略了對一些難纏的屬性講解,有避重就輕的嫌疑。CSS中主要難以理解的屬性包括盒型結構,以…

Java ObjectInputStream readLong()方法(帶示例)

ObjectInputStream類readLong()方法 (ObjectInputStream Class readLong() method) readLong() method is available in java.io package. readLong()方法在java.io包中可用。 readLong() method is used to read 8 bytes (i.e. 64 bit) of long value from this ObjectInputSt…

交換瓶子(藍橋杯)

有N個瓶子,編號 1 ~ N,放在架子上。 比如有5個瓶子: 2 1 3 5 4 要求每次拿起2個瓶子,交換它們的位置。 經過若干次后,使得瓶子的序號為: 1 2 3 4 5 對于這么簡單的情況,顯然,至少…

Linux設備驅動開發---字符設備驅動程序

字符設備驅動程序1 主設備和次設備的概念設備號的注冊和釋放靜態方法動態方法區別2 設備文件操作struct file_operations與struct file、struct inode關系3 分配和注冊字符設備class_createcdev_adddevice_create4 字符設備驅動程序字符設備通過字符(一個接一個的字…

Java LinkedHashMap getOrDefault()方法與示例

LinkedHashMap類的getOrDefault()方法 (LinkedHashMap Class getOrDefault() method) getOrDefault() method is available in java.util package. getOrDefault()方法在java.util包中可用。 getOrDefault() method is used to get the value associated with the given key el…

Java中的異常棧軌跡和異常鏈

Java中允許對異常進行再次拋出,以提交給上一層進行處理,最為明顯的例子為Java的常規異常。 常規異常:有Java所定義的異常,不需要異常聲明,在未被try-catch的情況下,會被默認上報到main()方法。 Example: pu…

貪心算法---背包問題(物品可以分割問題)

問題背景: 有一天,阿里巴巴趕著一頭毛驢上山砍柴。砍好柴準備下山時,遠處突然出現一股煙塵,彌漫著直向上空飛揚,朝他這兒卷過來,而且越來越近。靠近以后,他才看清原來是一支馬隊,他…

同步---信號量

信號量1 信號量2 驅動程序和測試程序3 內核的具體實現總結1 信號量 Linux中的信號量是一種睡眠鎖。如果有一個任務試圖獲得一個已經被占用的信號量時,信號量會將其放到一個等待隊列,然后讓其睡眠,這時處理器去執行其他代碼。當持有信號量的進…

Java Float類floatToIntBits()方法與示例

Float類floatToIntBits()方法 (Float class floatToIntBits() method) floatToIntBits() method is available in java.lang package. floatToIntBits()方法在java.lang包中可用。 floatToIntBits() method follows IEEE 754 floating-point standards and according to standa…

解釋三度帶和六度帶的概念以及各坐標系如何定義

★ 地形圖坐標系:我國的地形圖采用高斯-克呂格平面直角坐標系。在該坐標系中,橫軸:赤道,用Y表示;縱軸:中央經線,用X表示;坐標原點:中央…

0-1背包問題(物品不可分割)

問題背景: 所謂“鐘點秘書”,是指年輕白領女性利用工余時間為客戶提供秘書服務,并按鐘點收取酬金。“鐘點秘書”為客戶提供有償服務的方式一般是:采用電話、電傳、上網等“遙控”式 服務,或親自到客戶公司處理部分業務…

算法---KMP算法

字符串1 KMP算法狀態機概述構建狀態轉移1 KMP算法 原文鏈接:https://zhuanlan.zhihu.com/p/83334559 先約定,本文用pat表示模式串,長度為M,txt表示文本串,長度為N,KMP算法是在txt中查找子串pat&#xff0…

cache初接觸,并利用了DataView

我們在寫代碼的時候,如果數據控件要獲得數據,一般方法,Conn.Open();OleDbCommand cmd;cmd new OleDbCommand(sql, Conn);GridView1.DataSource dbcenter.accessGetDataSet(sql);GridView1.DataBind();Conn.close();但如果多個數據控件要綁定數據,則比較頻繁打開數據庫,效率一…

Java ByteArrayInputStream reset()方法及示例

ByteArrayInputStream類reset()方法 (ByteArrayInputStream Class reset() method) reset() method is available in java.util package. reset()方法在java.util包中可用。 reset() method is used to reset this ByteArrayInputStream to the last time marked position and …

回文數猜想

問題描述: 一個正整數,如果從左向右讀(稱之為正序數)和從右向左讀(稱之為倒序數)是一樣的,這樣的數就叫回文數。任取一個正整數,如果不是回文數,將該數與他的倒序數相加…

文件上傳 帶進度條(多種風格)

文件上傳 帶進度條 多種風格 非常漂亮&#xff01; 友好的提示 以及上傳驗證&#xff01; 部分代碼&#xff1a; <form id"form1" runat"server"><asp:ScriptManager ID"scriptManager" runat"server" EnablePageMethods&quo…

同步---自旋鎖

1 自旋鎖的基本概念 自旋鎖最多只能被一個可執行線程持有&#xff0c;如果一個執行線程試圖獲得一個已經被使用的自旋鎖&#xff0c;那么該線程就會一直進行自旋&#xff0c;等待鎖重新可用。在任何時刻&#xff0c;自旋鎖都可以防止多余一個的執行線程同時進入臨界區。 Linu…

實習日志----4.播放時段參數設置

由于客戶在下發廣告時&#xff0c;一則廣告可在多個時段播放&#xff0c;這就需要設置多個播放時段的參數。 但在這種情況下&#xff0c;我并不知道用戶每次需要下發幾個時段&#xff0c;所以前臺不能設定死。 因此我要實現這么一個功能&#xff0c;讓用戶根據自己的需要來動態…