Package.getPackage in java returning null

喜夏-厌秋 提交于 2019-12-04 23:02:40

Package.getPackage will only return a non-null value if the current ClassLoader is already aware of the package. Try this:

Package pkg = Package.getPackage("com.abc");
System.out.println(pkg);
Class<A> a = A.class;
pkg = Package.getPackage("com.abc");
System.out.println(pkg);

The first System.out will print 'null', the second will print the package name as the ClassLoader has then loaded a class from it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!