Hi I did some reading and came across this behavior that I don't really know why is like this. Would love to get an explanation why it works like this.
class InputTest {
public static void main(String[] args){
System.out.println("WITHOUT array:");
byte a=0;
System.out.println(a);
test(a);
System.out.println(a);
System.out.println("WITH array:");
byte[] b={1,2,3,4,5};
System.out.println(b[3]);
test2(b);
System.out.println(b[3]);
}
static void test(byte a){
a=120;
}
static void test2(byte[] b){
b[3]=120;
}
}
printing of the code is:
WITHOUT array:
0
0
WITH array:
4
120
So I kinda want to understand why this is so maybe I don't make a unnecessary mistake in the future.