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

不羁岁月 提交于 2019-11-27 03:37:46

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3323608/how-is-javas-stringintern-method-implemented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!