提交 cc99a464 authored 作者: noelgrandin's avatar noelgrandin

avoid instantiating Boolean objects, rather use the predefined values in java.lang.Boolean

上级 9686ba35
...@@ -75,7 +75,7 @@ public class SupportedTypes { ...@@ -75,7 +75,7 @@ public class SupportedTypes {
static SupportedTypes randomValue() { static SupportedTypes randomValue() {
Random rand = new Random(); Random rand = new Random();
SupportedTypes s = new SupportedTypes(); SupportedTypes s = new SupportedTypes();
s.myBool = new Boolean(rand.nextBoolean()); s.myBool = Boolean.valueOf(rand.nextBoolean());
s.myByte = new Byte((byte) rand.nextInt(Byte.MAX_VALUE)); s.myByte = new Byte((byte) rand.nextInt(Byte.MAX_VALUE));
s.myShort = new Short((short) rand.nextInt(Short.MAX_VALUE)); s.myShort = new Short((short) rand.nextInt(Short.MAX_VALUE));
s.myInteger = new Integer(rand.nextInt()); s.myInteger = new Integer(rand.nextInt());
......
...@@ -906,7 +906,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -906,7 +906,7 @@ public class TestPreparedStatement extends TestBase {
stat.execute("INSERT INTO TEST VALUES(1, 'Hello')"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
PreparedStatement prep = conn PreparedStatement prep = conn
.prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST"); .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST");
prep.setObject(1, new Boolean(true)); prep.setObject(1, Boolean.TRUE);
prep.setObject(2, "Abc"); prep.setObject(2, "Abc");
prep.setObject(3, new BigDecimal("10.2")); prep.setObject(3, new BigDecimal("10.2"));
prep.setObject(4, new Byte((byte) 0xff)); prep.setObject(4, new Byte((byte) 0xff));
...@@ -929,7 +929,7 @@ public class TestPreparedStatement extends TestBase { ...@@ -929,7 +929,7 @@ public class TestPreparedStatement extends TestBase {
prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER); prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER);
rs = prep.executeQuery(); rs = prep.executeQuery();
rs.next(); rs.next();
assertTrue(rs.getObject(1).equals(new Boolean(true))); assertTrue(rs.getObject(1).equals(Boolean.TRUE));
assertTrue(rs.getObject(2).equals("Abc")); assertTrue(rs.getObject(2).equals("Abc"));
assertTrue(rs.getObject(3).equals(new BigDecimal("10.2"))); assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
assertTrue(rs.getObject(4).equals((byte) 0xff)); assertTrue(rs.getObject(4).equals((byte) 0xff));
......
...@@ -48,7 +48,7 @@ public class ClassUtils { ...@@ -48,7 +48,7 @@ public class ClassUtils {
} else if (clazz == Double.class) { } else if (clazz == Double.class) {
return (T) new Double(COUNTER.getAndIncrement()); return (T) new Double(COUNTER.getAndIncrement());
} else if (clazz == Boolean.class) { } else if (clazz == Boolean.class) {
return (T) new Boolean(false); return (T) Boolean.FALSE;
} else if (clazz == BigDecimal.class) { } else if (clazz == BigDecimal.class) {
return (T) new BigDecimal(COUNTER.getAndIncrement()); return (T) new BigDecimal(COUNTER.getAndIncrement());
} else if (clazz == BigInteger.class) { } else if (clazz == BigInteger.class) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论