[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Constructing java.lang.String in constant pool

From: Jochen Hoenicke
Subject: Re: Constructing java.lang.String in constant pool
Date: Fri, 29 Jun 2001 10:24:22 +0200

On Jun 28, Tom Tromey wrote:
> >>>>> "Patrick" == Patrick Doyle <address@hidden> writes:
> Patrick> What is the best way for a JVM to instantiate a String for a
> Patrick> constant pool entry of type "CONSTANT_String"?
> Use the JNI `NewString' call.  It takes a nul-terminated UTF-8 encoded
> `char *' and returns a jstring.  The termination will probably be a
> problem for you :-(
> Or maybe you mean you want to implement this call.  In that case your
> plan of using String(char[]) sounds as good as any.

And don't forget to intern() the string.  From the JVM Spec:

The Java programming language requires that identical string literals
(that is, literals that contain the same sequence of characters) must
refer to the same instance of class String. In addition, if the method
String.intern is called on any string, the result is a reference to
the same class instance that would be returned if that string appeared
as a literal. Thus, ("a" + "b" + "c").intern() == "abc"
must have the value true.

You have some bootstrapping issues to resolve, since the class
java.lang.String also has some strings in its constant pool.  Maybe
it's easier to use the knowledge of the internal structure...


reply via email to

[Prev in Thread] Current Thread [Next in Thread]