I wonder how Java is handling me creating a bunch of Consumer instances.
I will elaborate for my current scenario. I'm making a small game. When loading the models & scenes, I'm linking a Scene (containing a Model) to for example a Entity. This Scene allows operations like changing the position. When linking a scene to my Entity, I also make sure to give the Entity a Consumer
Let's assume that I will use a Consumer<Pos> to handle position changes.
It would look like this:
class Entity {
Consumer<Pos> con;
void changePosition(Pos p) {
con.accept(p);
}
Consumer<Pos> init(Visitor v) {
this.con = v.load(this);
}
}
class Visitor {
Consumer<Pos> load(Entity e) {
GLTFModel m = new GLTF().load("");
Scene s = new Scene(m);
return (pos) -> s.setPos(pos);
}
}
I will probably use another way of doing this. I wonder what would happen to performance if I had about 1000 or more of these Consumer<Pos> registered. Is it bad for memory? Is it encouraged to do something like this?