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
Post a Comment