在不同项目之间重用代码和通用实现

Reusing code and generic implementations between different projects

在我看来,在很多情况下,不同项目的特定 class 实现是相同的。

在 Java 中,这适用于像 ArrayList 这样的 classes。因此,显然有理由在不同项目中重用通用 classes。

另一个有用的通用 class 是 ArrayMatrix,但由于 Java 中没有默认实现,我自己做了一个。它是通用的、安全的和有记录的。

在这种情况下创建您自己的实施是常见的做法吗?

如果没有,首选方式是什么?

如果是,那么在项目之间共享 class/code 和组织“库”的最佳做法是什么?

这就是拥有 库的全部意义所在。共享它们的最佳方式是将它们放在工件存储库中;如果可以的话,Central and JCenter, or some company-internal repository if the libraries can't be open-sourced for some reason. Here's the intro to publishing to Central; it's a minor hassle, but I've done it myself,也不是太难。

我鼓励您确保在 Guava 或 Apache Commons 中没有与您的 class 等效的东西。