How is Java's String#intern() method implemented?
Asked Answered
V

1

7

I tried to look at Java's String#intern() method, but it's public native String intern();

In general, how is interning implemented? In String's case?

Valiancy answered 24/7, 2010 at 2:49 Comment(0)
U
14

For Sun Java, start with JVM_InternString, on line ~3639 of jvm.cpp. Technically, the actual String method is in java/lang/String.c, but it immediately calls JVM_InternString. You can continue to StringTable::intern in symbolTable.cpp.

In a more abstract sense, the purpose of interning is to map equivalent strings to a single canonical one.

Unbeliever answered 24/7, 2010 at 3:1 Comment(2)
Hmm, it would have been nice to show some code in the question. All the links are broken now. Thank you for the good start though.Treen
All the links work fine for me. They definitely aren't broken anymore!Crappie

© 2022 - 2024 — McMap. All rights reserved.