Hi
I think that was due to local objects creation each time on same
memory space.
But I wonder when I test it as instance variable. I found more
confusing results.
I run two instances of JVM. Code is as under
JVM 1:
public class Test1 {
int i = 0;
static Test1 o[] = new Test1[10];
public static void main(String[] args) throws InterruptedException
{
Thread t = new Thread(){
public void run(){
for(int i = 0; i < 10; i++){
o[i] = new Test1();
System.out.println(o[i].hashCode());
o[i].i = i;
}
}
};
t.start();
Thread.sleep(8000);
for(int i = 0; i < 10; i++){
System.out.println(o[i].i);
}
}
JVM 2:
public class Test1 {
int i = 0;
static Test1 o[] = new Test1[10];
public static void main(String[] args) throws InterruptedException
{
Thread t = new Thread(){
public void run(){
for(int i = 0; i < 10; i++){
o[i] = new Test1();
System.out.println(o[i].hashCode());
}
}
};
t.start();
Thread.sleep(1000);
for(int i = 0; i < 10; i++){
System.out.println(o[i].i);
}
}
I run JVM 1 and then JVM 2.
Both the JVMs print same hashcode for objects, but values were
different.
If native hashcode has something to so with addresses then both JVMs
generated same addresses and they should have same values each time.?
Still trying to find the solution... ?