This site requires JavaScript, please enable it in your browser!
Greenfoot back
jbafs
jbafs wrote ...

2024/3/23

Constructor class not found

jbafs jbafs

2024/3/23

#
For some reason, Greenfoot can't find the Constructor<T> class.
public <T extends Entity> void spawnEntities(Class<? extends Entity> entityType){
      Constructor<T> constructor = entityType.getConstructor(Integer.class, Integer.class);
      constructor.newInstance(0, 0);
    }
It's in the docs, I've tried importing the class, it just doesn't work. The code also doesn't work for other reasons, but if I can figure this out then it'll work
Spock47 Spock47

2024/3/23

#
Do you have an import statement for it at the beginning of the file?
import java.lang.reflect.Constructor;
Live long and prosper, Spock47
jbafs jbafs

2024/3/23

#
yea so I solved the problem.
You need to login to post a reply.