mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add Intern
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user