简体   繁体   中英

How to declare and call a java method which takes two dimensional bye array parameter from RPG?

I have a java method one of whose arguments is a 2 dimensional byte array ( byte[][] ). I wanted to call that method from RPG. I know that it works for one dimensional byte array eg by declaring that argument in RPG as nA where n is the length of the array and A is Alphabetic. ie nA in RPG is same as byte[] in java. However when I add DIM(k) to the argument declaration RPG, it says Keyword is not allowed in a prototype of a method. I could do it using String data type but I wanted to avoid data type conversions like from bytes to java String and vice-versa. (efficiency issues)

Can anyone help me with getting it work, please?

I think that the way to go here from a code-compileability and readability perspective is to use a simple data-wrapper class holding a one-dimensional array, and then let your main-code use a one-dimensional array of instances of said data-wrapper class.

public class MyBytePacket
{
    private byte [] data;

    //Constructors and getters as needed
}

And then from main code;

MyBytePacket [] packets = new MyBytePacket[10];

That way, you can see how many packets you have, as well as how many bytes each packet has, keeping your desired 2D-aspect, but in a more Java-friendly manner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM