-1

I am making a subroutine that will convert a 8-bit binary number into a int value. I want it to take as a parameter a int array with a length of 8 (to represent the binary number) and reject arrays of any other length. Is the possible?

2
  • 1
    No. You can check the length in your method. Commented Jun 16, 2017 at 10:06
  • You can check for the length of the given array at the start of the method and throw an exception / return null. Commented Jun 16, 2017 at 10:06

1 Answer 1

1

It is not possible to ensure the length of an array at compile time. You have to use

if(my_array.length != 8){
    throw new Exception("Array must have a length of 8.");
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.