Problem is, that [patch0, patch1]
is an array of byte[]
arrays. It's not an array concatenation. Its [[0, 2, 4, 8, 16], [0, 3, 6, 12, 24]]
which cannot be cast to byte[]
You could use flatten()
method like
def p = [patch0, patch1].flatten() as byte[]
Or do smth like
((patch0 as List) + (patch1 as List) ) as byte[]
Or you can ommit a cast
def patch0 = [0, 2, 4, 8, 16] // will be Collection instance
def patch1 = [0, 3, 6, 12, 24]
(patch0 + patch1) as byte[] // You can plus collections, and then cast.
Versions above is Groovyer, but may be not as optimal.
Maybe faster solution will be smth from, How can I concatenate two arrays in Java? but most of all solutions there are verbose, Java-way, or use external libraries like ApacheCommon
Or look a t specific byte array Java concatenation. Easy way to concatenate two byte arrays