Thursday, 26 September 2013

I want dynamic way to get the package name from any class in java

I want dynamic way to get the package name from any class in java

I have code like below sample. in that I am telling the class_name to get
package name. instead of this method, i need another logic to get the
package name withoud telling the class_name directly.
package smk.jsf.bean;
public class test {
public static void main(String[] args) {
System.out.println(test.class.getPackage().getName());
//Is there any option like "this.class.getPackage().getName();" bz. i
don't want use class_name direclty
}
}
Output : smk.jsf.bean

No comments:

Post a Comment