lundi 23 mars 2015

Java how to access another package and class using a variable [duplicate]


This question already has an answer here:




Using Java, I'm trying to access a package using an integer ID variable in order to get a packages named "test.company1" and "test.company2". I would then like to create objects of a class named "Products" that is within both packages. What would be the best way?



Package pkg = Package.getPackage("test.company"+companyId);
Class company1 = pkg.getClass("Products");
//to then be able to do something like
//test.company1.Products products = new test.company1.Products();
//and test.company2.Products products = new test.company2.Products();





Aucun commentaire:

Enregistrer un commentaire