如何将byte []传递给此函数

Ang*_*ber 2 java

我有这个签名的功能:

void insert(T[] thearray);
Run Code Online (Sandbox Code Playgroud)

我有一个像这样的字节数组:

byte[] value = new byte[4096];
Run Code Online (Sandbox Code Playgroud)

但是,如果我这样调用函数:

cb.insert(值);

我收到一个错误:

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

CircularBuffer是带有insert方法的类.

我像这样实例化CircularBuffer:

CircularBuffer<Byte> cb = new CircularBuffer<Byte>(4096);
Run Code Online (Sandbox Code Playgroud)

如何将值传递给此插入函数?

为了清楚起见,CircularBuffer类声明如下:

public class CircularBuffer<T>

public CircularBuffer(int size) //ctor
Run Code Online (Sandbox Code Playgroud)

如果您需要更多细节:

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

EDIT到底为了效率原因我决定创建一个专门的ByteCircularBuffer. - 使用字节.这种原始类型到对象类型的区域,例如byte - > Byte令人困惑.

Oli*_*rth 6

A byte[]不是Byte[].您需要先将一个显式转换为另一个.

请参阅例如Cast ArrayList of wrappers到相应的基元数组,以获取执行此操作的可能方法.