java - Why is String.intern() a native method? -


what's logic behind making method native?

what advantage on making interned string pool hash map?

it looks little strange, seems it'd pretty easy 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 native code then?

it seems it'd pretty easy in non-native code ...

you're wrong. specification, string.intern() must interact constant pool, meet requirement 'all literal strings interned'. can't done java code.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -