Reputation: 16535
in java I can create byte array: byte[] array = new byte[] { 0, 0, 0, 0, 0 };
but this construct is invalid in groovy. How I can create byte array in groovy ?
Upvotes: 35
Views: 28307
Reputation: 41767
The following should suffice:
def array = [0, 0, 0, 0, 0] as byte[]
Have a look here for more details on arrays in groovy.
Upvotes: 45
Reputation: 3273
You can't initialize a literal array the same way because Groovy thinks the curly brackets form a closure. What you want is something like
def x = [ 0, 0, 0, 0, 0 ] as byte[]
See more: here
Upvotes: 5
Reputation: 171144
In addition to rich.okelly's answer,
byte[] array = [0, 0, 0, 0, 0]
works as well
Upvotes: 19