allocate array during run-time

W

Wizumwalt

I'm trying to allocate an IntBuffer during run-time once I know the
size I need but I can't get the following to compile. Eclipse
highlights the reason as such ...

Code:
Syntax error on token "]", VariableDeclaratorId expected after this
token.

Code:
private IntBuffer[] indBuffers;

public void myMethod(int val) {
indBuffers[] = BufferUtils.newIntBuffer[val];
// error in above line
...
 
M

Mark Thomas

I'm trying to allocate an IntBuffer during run-time once I know the
size I need but I can't get the following to compile. Eclipse
highlights the reason as such ...

Code:
Syntax error on token "]", VariableDeclaratorId expected after this
token.

Code:
	private IntBuffer[] indBuffers;

	public void myMethod(int val) {
		indBuffers[] = BufferUtils.newIntBuffer[val];[/QUOTE]
Leave out the [] - the name of the variable is just indBuffers.[QUOTE]
// error in above line
...
Mark
 
O

Oliver Wong

I'm trying to allocate an IntBuffer during run-time once I know the
size I need but I can't get the following to compile. Eclipse
highlights the reason as such ...

Code:
Syntax error on token "]", VariableDeclaratorId expected after this
token.

Code:
private IntBuffer[] indBuffers;

public void myMethod(int val) {
indBuffers[] = BufferUtils.newIntBuffer[val];
// error in above line
...

Assuming BufferUtils.newIntBuffer is an IntBuffer[][], then you would write
something like:

<code>
indBuffers = BufferUtils.newIntBuffer[val];
</code>

but if BufferUtils.newIntBuffer is actually a method which takes a single
integer as an argument and returns IntBuffer[], then you would write
something like:

<code>
indBuffers = BufferUtils.newIntBuffer(val);
</code>

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top