• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get address of String object?

 
Sam Drake
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Say I have the following statement:
String s1 = "abc";
How can I get the address of the memory for the variable s1?
I'm a beginner with a C background.
Drake.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, at least not in the Java language (or in any code running on the JVM itself.) Java's pointers aren't addresses. The concept of pointer/address equivalence is not part of the JVM architecture.
In C/C++ code using the Java Native Interface (JNI), which Java code can call out to, you can get a more or less opaque handle to the JVM's data structure representing that String object, but it's not really "a pointer to the String", either.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic