java默认包的使用
最近在写java测试程序的时候突然遇到了一个问题:java默认包中的public类是不能在其他包中直接调用的
首先,总结一下默认包中类的使用范围,java默认包中的类可以实例化其它包中的public类,但是其它包中的类是不能显式实例化默认包中的类这个特性在JDK1.4以后的版本成立;
其次,可以通过反射来访问默认包中的类,例如下面代码
public class Hello {
private String codeing;
public String getCodeing() {
return codeing + " Hello!";
}
public void setCodeing(String codeing) {
this.codeing = codeing;
}
}
package junit;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import junit.framework.Assert;
import junit.framework.TestCase;
public class TestHello extends TestCase{
public void testDplit() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException{
Class c = Class.forName("Hello");
Method m1 = c.getDeclaredMethod("setCodeing", String.class);
Object ins = c.newInstance();
m1.invoke(ins, "qh");
Method m2 = c.getDeclaredMethod("getCodeing");
Assert.assertEquals((String)m2.invoke(ins),"qh Hello!");
}
}
相关文档:
一. Incident
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
......
Cavaj Java Decompiler is a graphical freeware utility that reconstructs Java source code from CLASS files. You can decompile Java applets, JAR and ZIP files, producing accurate Java source code. Browse the reconstructed source code with the Class View for instant access to methods and fields. The pr ......
如果你升级到了1.3.3,并且deploy了新版本的应用,会发现
Error: Not Found
The requested URL /login
was not found on this server.
很悲剧,原因与filter设置有关(和程序无关,是sdk的问题),issue已经有了。
解决办法:
升级到1.3.3.1,下载地址
用ec插件仍然无法更新,下载sdk解压到X:\eclipse\plugins\com. ......
豆豆网 技术应用频道 2009年06月10日 【字号:小中大】 收藏本文
JProfiler memcached JavaCC EclEmma Jester Java加密技术(七)。
ECC
ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制。在软件注册 ......