簡體   English   中英

如何將byte []傳遞給此函數

[英]How to pass a byte[] to this function

我有這個簽名的功能:

void insert(T[] thearray);

我有一個像這樣的字節數組:

byte[] value = new byte[4096];

但是,如果我這樣調用函數:

cb.insert(值);

我收到一個錯誤:

The method insert(Byte) in the type CircularBuffer<Byte> is not applicable for the arguments (byte[])

CircularBuffer是帶有insert方法的類。

我像這樣實例化CircularBuffer:

CircularBuffer<Byte> cb = new CircularBuffer<Byte>(4096);

如何將值傳遞給此插入函數?

為了清楚起見,CircularBuffer類聲明如下:

public class CircularBuffer<T>

public CircularBuffer(int size) //ctor

如果您需要更多細節:

https://codereview.stackexchange.com/questions/22826/circular-buffer-implementation-for-buffering-tcp-socket-messages

EDIT到底為了效率原因我決定創建一個專門的ByteCircularBuffer。 - 使用字節。 這種原始類型到對象類型的區域,例如byte - > Byte令人困惑。

byte[]不是Byte[] 您需要先將一個顯式轉換為另一個。

請參閱例如Cast ArrayList of wrappers到相應的基元數組,以獲取執行此操作的可能方法。

Bytebyte完全不同。 將字節數組轉換為字節數組(這需要大量時間和內存),或者編寫新類ByteCircularBuffer (使用CircularBuffer<T>並將T替換為byte )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM