我发现自己检查了这一点,并询问是否有必要.我有这样的代码:
public Object myMethod(Object... many) {
if (many == null || many.length == 0)
return this;
for (Object one : many)
doSomethingWith(one);
return that;
}
Run Code Online (Sandbox Code Playgroud)
但后来我想知道......我是否过于谨慎?我需要检查一下many == null吗?在任何当前的Java版本中都有可能吗?如果是这样,怎么样?如果没有,我可能会继续检查,只是为了防止以后Oracle确定它有一天可以为空.
阅读最近的一个问题,我确定了正在讨论的功能
(def fib-seq
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
Run Code Online (Sandbox Code Playgroud)
虽然抓住了一个序列的头部,但是我想到了重新阅读我的答案,我已经掩盖了细节,就像他们很明显一样,所以我回过头来澄清并且做得很短.我知道fib-seq是一个var,只要它在它周围就能保存序列中的所有元素,但我根本不清楚序列是如何被保持的确切机制.任何澄清将不胜感激.
我差不多完成了scala书,我想要一些很好的代码示例,它可以帮助我巩固我所学到的知识.
你可以推荐github上有什么吗?
最好是某种我可以学习的库,也许是一个API包装器?或者你推荐的其他东西?
我一直听到很多关于不同的JVM语言,仍然处于汽化模式,建议以某种方式实现具体化.我有一半的记忆(或完全想象,不知道哪个),我认为Scala以某种方式利用JVM的类型擦除做了一些它无法用于具体化的事情.由于Scala是在CLR和JVM上实现的,因此对我来说没有任何意义,所以如果reification会引起某种限制,它会出现在CLR实现中(除非CLR上的Scala只是忽略了具体化) .
那么,为Scala键入擦除是否有好的一面,或者物化是一件毫不畏惧的好事?
我的应用程序在多个线程中执行多个查询
现在我正在为每个查询创建新连接,我想使用池来提高效率.
Apache DBCP池可以同时在多个线程中工作,还是会在每个线程上"阻塞"某些同步方法?
如果它阻止,我可以使用其他东西吗?
UPDATE
在本文中:链接 说明:
由于所有Oracle JDBC API方法都是同步的,如果两个线程同时尝试使用连接对象,则会强制其中一个等待,直到另一个完成其使用.
所以我猜DBCP将无法解决这个问题?
我也意识到在这种情况下池不会帮助我,因为每个线程都会请求连接,并且线程每次都会生成一个新连接(直到某些线程结束并返回到池的连接)
我在数据访问对象中有一个Java方法.这个非常简单的方法将两个整数值插入数据库.
public void saveHourMin(int hour, int min) throws SQLException{
psInsert.setInt(1, hour);
psInsert.setInt(2, min);
psInsert.executeUpdate();
}
Run Code Online (Sandbox Code Playgroud)
这个方法,或者一般来说,任何DAO方法,抛出SQLException时是抛出异常,还是应该捕获并记录异常,然后通过返回代码通知用户?使用Spring的应用程序的正确方法是什么?
AtomicReference和Synchronized之间有什么区别吗?
例如
public class Internet {
AtomicReference<String> address;
public String getAddress(){
return address.toString();
}
public void setAddress(String address) {
this.address.set(address);
}
}
Run Code Online (Sandbox Code Playgroud)
我将类传递给一些尝试同时使用该类的线程,如果我使用它是同样的事情:
public class Internet {
String address;
public String getAddress(){
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在线程使用synchronized之前访问类?
给出以下Java代码:
public class Test {
static private class MyThread extends Thread {
private boolean mustShutdown = false;
@Override
public synchronized void run() {
// loop and do nothing, just wait until we must shut down
while (!mustShutdown) {
try {
wait();
} catch (InterruptedException e) {
System.out.println("Exception on wait()");
}
}
}
public synchronized void shutdown() throws InterruptedException {
// set flag for termination, notify the thread and wait for it to die
mustShutdown = true;
notify();
join(); // lock …Run Code Online (Sandbox Code Playgroud) 如何使用assertEquals查看异常消息是否正确?测试通过,但我不知道它是否达到了正确的错误.
我正在运行的测试.
@Test
public void testTC3()
{
try {
assertEquals("Legal Values: Package Type must be P or R", Shipping.shippingCost('P', -5));
}
catch (Exception e) {
}
}
Run Code Online (Sandbox Code Playgroud)
正在测试的方法.
public static int shippingCost(char packageType, int weight) throws Exception
{
String e1 = "Legal Values: Package Type must be P or R";
String e2 = "Legal Values: Weight < 0";
int cost = 0;
if((packageType != 'P')&&(packageType != 'R'))
{
throw new Exception(e1);
}
if(weight < 0)
{
throw new Exception(e2);
} …Run Code Online (Sandbox Code Playgroud) 我知道有类似这个问题的线程.下面是我的类,我在spring.xml文件中配置它.实际上HumanResourceService是一个只有一个方法的接口.
@Endpoint
public class HolidayEndpoint {
@Autowired
private HumanResourceService humanResourceService;
@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException {
this.humanResourceService = humanResourceService;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在我的spring.xml文件中,当我将HumanResourceService定义为bean时,它无法实例化,因为这是一个接口.如何在spring配置文件中提及接口.我的spring.xml文件如下
<bean id="holidayEndpoint" class="com.mycompany.hr.ws.HolidayEndpoint" autowire="constructor" >
<property name="humanResourceService" ref="humanResourceService" />
</bean>
<bean id="humanResourceService" class="com.mycompany.hr.service.HumanResourceService" />
Run Code Online (Sandbox Code Playgroud) java ×6
scala ×2
spring ×2
architecture ×1
atomic ×1
clojure ×1
dao ×1
exception ×1
java-ee ×1
join ×1
junit ×1
junit4 ×1
notify ×1
null-check ×1
reification ×1
synchronized ×1
type-erasure ×1
type-systems ×1
wait ×1