为什么Java Swing中的JTable使用Vector作为构造函数参数? [英] Why does JTable in Java Swing use Vector as constructor params?

查看:823
本文介绍了为什么Java Swing中的JTable使用Vector作为构造函数参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道为什么 JTable 在Java Swing中使用Vector作为构造函数params:喜欢 JTable(Vector rowData,Vector columnNames),虽然Vector被标记为过时的集合。 (我知道还有其他选项,但使用Vector更方便)。它有与线程同步有关的任何内容吗?

Does anyone know why JTable in Java Swing use Vector as constructor params: like JTable(Vector rowData, Vector columnNames), although Vector is marked as obsolete collection. (I know there are other options too but using Vector is much more convenient). Does it have anything related to thread synchronization?

推荐答案

Vector 既不过时也不过时,它是遗产原始 DefaultTableModel ;后来,它被改装以实施 列出 界面。 Vector 已同步,但正确使用此功能有效地依赖于实现细节。相反,依赖于 类的内存一致性属性 ,其方法提供发生在之前的关系。例如, SwingWorker ,实现 Future< T> RunnableFuture< T> ,特别方便用于在事件派发线程上可靠地更新表格模型。这样就不需要冗余地同步模型的内部数据结构。

While Vector is neither obsolete nor deprecated, it is a legacy of the original DefaultTableModel; later, it "was retrofitted to implement the List interface." Vector is synchronized, but using it correctly for this feature effectively relies on an implementation detail. Instead, rely on the Memory Consistency Properties of classes whose methods provide a happens-before relation. For example, SwingWorker, which implements Future<T> and RunnableFuture<T>, is particularly convenient for reliably updating a table's model on the event dispatch thread. This obviates the need to synchronize the model's internal data structure(s) redundantly.

这篇关于为什么Java Swing中的JTable使用Vector作为构造函数参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆