What's the logic behind making this method native?
What is the advantage over just making the interned String pool with a hash map?
It looks a little strange, but it seems like it'd be pretty easy to do in non-native code:
import java.util.HashMap;
public class String {
// ...
private final static HashMap<String, String> pool = new HashMap<>();
public String intern() {
if (pool.containsKey(this))
return pool.get(this);
synchronized (pool) {
if (pool.containsKey(this))
return pool.get(this);
pool.put(this, this);
return this;
}
}
// ...
}
So why is it native code then?