2

I have a function with this signature:

void insert(T[] thearray);

And I have a byte array like this:

byte[] value = new byte[4096];

But if I call function like this:

cb.insert(value);

I get a error:

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

CircularBuffer is the class with the insert method.

I instantiate CircularBuffer like this:

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

How can I pass the value to this insert function?

To be clear, the CircularBuffer class is declared like this:

public class CircularBuffer<T>

public CircularBuffer(int size) //ctor

More details if you need:

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

EDIT in the end I decided for efficiency reasons to create a specialised ByteCircularBuffer. - using byte. This area of primitive type to object type, eg byte -> Byte is confusing.

Community
  • 1
  • 1
Angus Comber
  • 9,316
  • 14
  • 59
  • 107

2 Answers2

6

A byte[] is not a Byte[]. You will need to explicitly convert one to the other first.

See e.g. Cast ArrayList of wrappers to corresponding array of primitives for possible ways to do this.

Community
  • 1
  • 1
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
2

Byte is quite different from byte. Either convert array of bytes to array of Bytes (this requires lot of time and memory), or write new class ByteCircularBuffer (take CircularBuffer<T> and replace T with byte).

Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38
  • I tried this: class ByteCircularBuffer extends CircularBuffer { } but then get errors: Multiple markers at this line. - Syntax error on token "byte", Dimensions expected after this token. - Syntax error on token(s), misplaced construct(s) – Angus Comber Feb 17 '13 at 17:46
  • Yup. You can't have `ByteCircularBuffer` extend `CircularBuffer`. You have to make an entirely separate class. – Louis Wasserman Feb 17 '13 at 18:49