是否可以从 Class 类型的 ArrayList 中调用方法?

Is it possible to call a method from within an ArrayList of type Class?

我有一个 class public ArrayList<Spheres> sphereList = new ArrayList<Spheres>(10); 的 ArrayList,我需要从 class Spheres 中调用一个方法来更新 sphereList 中的所有元素].这可能吗?如果可以,我将如何去做?如果不可能,是否有我应该采取的替代方法?

一切皆有可能...

-您必须将父项 class 的引用传递给 Spheres

的每个实例

-或者使用 Observer - 可观察设计模式

-或者将 ArrayList 更改为 LinkedList,在调用方法时更新引用链。

sphereList.stream().forEach(x -> x.callMethodFromSphere());