add Intern

This commit is contained in:
Looly
2020-09-16 00:45:22 +08:00
parent d8e7cdde79
commit 667dbc2be7
7 changed files with 134 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
package cn.hutool.core.lang.intern;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
public class InternUtilTest {
/**
* 检查规范字符串是否相同
*/
@SuppressWarnings("StringOperationCanBeSimplified")
@Test
public void weakTest(){
final Interner<String> interner = InternUtil.createWeakInterner();
String a1 = RandomUtil.randomString(RandomUtil.randomInt(100));
String a2 = new String(a1);
Assert.assertNotSame(a1, a2);
Assert.assertSame(interner.intern(a1), interner.intern(a2));
}
}