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

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -