java how to get the primitive type variable memory address? How to get the memory address of the String variable?

Category: Java SE
 
wuyuheng666
2009-04-11 02:43:00

Sponsored Links
Basic variable is initialized when it is assigned a memory address
String variable is the same
But is there any way to get the memory address
Oh, the next concern

Sponsored Links

shaoxue613
2009-04-11 02:46:45
look! ! !
lfpluoxiao
2009-04-11 03:05:22
For the object by calling the hashCode () to get the memory address.
primitive type variables I do not know.

import java.util. *;

public class InfiniteRecursion {
public String toString () {
return ; "address:" + Integer.toHexString (hashCode ()) + "\ n";
}
public static void main ( String [] args) {
List v = new ArrayList ();
for (int i = 0; i < ; 10; i + +)
v.add (new InfiniteRecursion ());
System.out.println (v);
}
}
ggggssss
2009-04-11 03:14:48
Object hashCode in fact, is to return the address of the object in the JVM, so a very simple way!
For any object, this method does not directly call the following to get without a rewrite before hashCode?
System.identityHashCode (Object obj);
rainly123
2009-04-11 03:25:12
Can you guarantee hashCode () implementation is the memory address of the object to get it?
such as String object whose hashCode () get is String.toString () results!
andywn
2009-04-11 03:36:29
I'm talking about is the use of java.lang.object.hashCode ();
I'm just learning java, java remember the book said on java.lang.object.hashCode (); is returns the address of the object in memory to achieve.
public class StrAddr {
public static void main (String [] args) {
; String a = "123";
String b = "456";
System.out.println ("String Value Address:" + Integer. toHexString (a.hashCode ()));
System.out.println ("String Value Address:" + Integer.toHexString (b.hashCode ()));
}
}
hua8856835
2009-04-11 03:46:53
Do you know the String hashCode () method is how count out of it?
Returns a hash code for this string. The hash code for a String object is computed as
s [0] * 31 ^ (n-1) + s [1] * 31 ^ (n-2) + ... + s [n-1

not an object address
hgj99991
2009-04-11 04:00:14
If you can get the memory address java inside if not that, and C + + pointers inside yet? Memory addresses that can manipulate things on
I learned people know java, java there is no pointer is to prevent the memory to manipulation and then, if there is some way to get the memory address it not self- contradictory?
this is a personal opinion, provided that I do not know how to get memory address
wangpl4092
2009-04-11 04:08:03
public class PassReferences {
public PassReferences () {
}
static void f (PassReferences h) {
System.out.println ("h inside f (): "+ h);
}

public static void main (String [] args) {
PassReferences p = new PassReferences ();
System.out.println ("p inside main ( ): "+ p);
f (p);

}

}
This is thinking in java routines, used to get PassReferences address of the object, call the Object.toString () method is a user-defined object PassReferences address; That is some object memory address can be obtained,
aimodan
2009-04-11 04:15:11
I think this can be said:
assume a Class not implemented toString (), including its removal of all except Object superclass, then call the object's toString method will also be its object memory address

but no way to get a type of object called a function of its parent type, which is closed dynamic binding, I think thinking in java say the function the final statement can be turned off dynamic binding, but only tells compiler: dynamic binding does not require, according to final method call allows compiler generates better efficiency program code, but does not guarantee compiler does not use dynamic binding

I do not know whether my understanding correct?
zssx888
2009-04-11 04:24:19
Object.toString implementation is
getClass (). getName () + '@' + Integer.toHexString (hashCode ())
is actually the Object hashCode method returns the object address. So you need to get the memory address to the Object class if not between classes to override hashCode (override), obtained by this method can object's memory address. On the contrary can not be obtained by this method, the memory address.
I think we should be able to pass a function to get the memory address of an object or variable, but we can not pass this address to operate its stored content.
ms123654987
2009-04-11 04:35:02
two objects the same value (x.equals (y) == true), but it may have a different hash code, this sentence right?

wrong, have the same hash code.
s418209737
2009-04-11 04:52:26
up!
xinnianyrien
2009-04-11 05:09:21

two objects the same value (x.equals (y) == true), but it may have a different hash code, this sentence right right?

wrong, have the same hash code.
---------------------
personally think hashCode is the only object in memory id, hashCode equal, that is, the same object
abide123
2009-04-11 05:12:48
Object hashCode in fact, is to return the address of the object in the JVM, so a very simple way!
For any object, this method does not directly call the following to get without a rewrite before hashCode?
System.identityHashCode (Object obj);
---------------------
"does not override before hashCode ", what does this mean ah? !
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.