Glen Mazza wrote:
No need-the "gotcha" site you gave earlier did give
some specific drawbacks under string compares:


http://mindprod.com/jgloss/gotchas.html#COMPARISON

That's not a drawback. Interned strings allow comparision of references: String a="a".intern(); String b="a".intern(); if(a==b) { System.out.println("equal"); } With non-interned strings you need a.equals(b), which may be slower, for longer strings anyway.

Same for the time needed for interning: I doubt a home
grown mechanism for this, which is exactly what Austin
proposes, would be more efficient.

The most important gotcha is that interned strings may lock
up memory forever. If interning is done only for property
names and enumeration tokens (in contrast to property values),
this may be acceptable.

J.Pietschmann




Reply via email to