以下代码给出了编译时错误:缺少返回值和缺少return语句,我将返回什么值Void Type?
final SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>()
{
@Override
protected Void doInBackground() throws Exception
{
// some code
if (something)
{
return;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我做了一些修改,我的多线程程序,并开始获得ConcurrentModificationException一个物体的S- HashTable,所以我做的所有访问在此HashTable为synchronised方法,以避免并发访问我的对象,不像我期望它并没有解决问题.以下是使用的设计概述:
首先,我有一个JTable显示usb设备的一些数据,这JTable要求一个通信核心对象实现Observer(通过Observable对象读取和写入数据到我的设备)它想要的数据,它想要的数据取决于显示哪些行,以便在用户滚动de table时更新,此通信核心对象通过synchronized update调用其他synchronized更新方法的方法获取此通知,该方法HashTable保存最后读取的值(使用后此通信类通知我的JTable类)和其他对象,当它通过其他Observable对象读取值时).更新时,最后一种方法出现异常HashTable.这是代码的简化:
以下方法是通信核心对象
public synchronized void update(Observable o, Object arg)
{
// do some other work
// calls the second synchronized method
updateMonitorList();
}
private synchronized void updateMonitorList()
{
// updates a list of monitoring addresses (no problem here)
// m_lastValues is the HashTable that is giving me headaches
Iterator<Parameter> …Run Code Online (Sandbox Code Playgroud)