1.Is there a keyword to refer to the current package that you are working in Java. Like we have "this" to refer to the current object. So , is there something similar for a package?
2.Also if the current class that I am working on is in a directory which has other classes,and my class has no package statement, then it will be in the default package. So, is there any way to import rest of the classes in the directory. I know that we can specify the classpath while compiling, but is there any way to do it using imports ?
The first one
No keyword
like this
to get package name
, but you can get package name
by java reflection
, like the following code
package com.netease.unitest.controller;
public class GenTest {
public static void main(String[] args) {
System.out.println(GenTest.class.getPackage().getName());
}
}
the output is
com.netease.unitest.controller
you can get more details in the following link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.