I am working on a JavaCard, so a SIM card that runs Java (or a subset of it: Java Embedded). Due to memory limitations I have an array that I reuse for multiple tasks.
I want a function to basically return a pointer to that array, with an offset, thus a slice. This way I can be sure that no part of that array will be overwritten by accident.
Pointers dont exactly exist in Java, but is there a way to return a part of an array without copying it?
No, this is not possible. Object (references) is the closest you can get to pointers in Java.
If this were regular Java, I would have suggested, to wrap the array in a
ListwithArrays.asListand then use theListmethodsubList, which provides a view of a section of the list without copying its contents.However If I read the JavaCard API reference correctly these aren't included. You could try write a simple version of those interfaces/classes/methods yourself.