我正在尝试使用动态绑定(bind)来创建“ByteCode
”对象。我在下面使用这个语句,但我对路径应该是什么样子感到困惑。
在 netbeans 中,我有一个名为 interpreter
的项目和一个包含 ByteCode
子类的 java 包 bytecode
。
我猜测它应该是 ("interpreter/bytecode.")
但不确定。
谢谢
bytecode = (ByteCode)(Class.forName("path/exampl/path."+codeClass).newInstance());
最佳答案
您应该为 forName 方法提供类的完整限定名称。
示例:
Class.forName("com.mysql.jdbc.Driver").newInstance();
关于java - 如何指定 java 包的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36365449/