1
scala 惰性演示:
private lazy val conn = DriverManager.getConnection("jdbc: full url....")
java演示:
public class LazyReferenceTest
{
private final LazyReference<Connection> conn = LazyReference.goLazy(() -> {
try {
return DriverManager.getConnection("jdbc:url....");
}
catch (SQLException e) {
throw new RuntimeException("Connection create fail", e);
}
});
// .....
}