开发者

Can Java Array objects be created dynamically at Runtime?

开发者 https://www.devze.com 2022-12-11 07:03 出处:网络
Can I do this in Java? At Runtime: int length = some arithmetic that loads length thenI use length to do this:开发者_Go百科

Can I do this in Java?

At Runtime:

int length = some arithmetic that loads length

then I use length to do this:开发者_Go百科

byte [] b = new byte[length];

Will this throw an Exception at Runtime? If so which one?


No that won't throw an exception at runtime, unless of course length is negative.


Yes it can be created at run time.

But you should try and see :)


i think you are forgetting the basic concept as objects are created at comile time and memory is allocated at run time.

0

精彩评论

暂无评论...
验证码 换一张
取 消