Java, get package name of class from string -


all have:

string desiredclass = "myclass"; 

i want instantize class, name comes string. know can done with:

class.forname(desiredclass); 

formula, need package path string (name.space.path.myclass). know can queried .getpackage() - again, needs direct class reference, not string. looks snake has bitten end :)

you need know package name before initializing object. without wouldn't able distinct 2 classes same name 2 separate packages.

if had 2 classes test1.myclass , test2.myclass 1 should chosen in code:

string desiredclass = "myclass"; class.forname(desiredclass); 

so need know package name in advance , like:

string desiredclass = "test1.myclass"; 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

Error while updating a record in APEX screen -

c++ - In an add-in in Excel, written in C(++), how does one get the name of the function which called into the addin? -