与Java 9中一样,一些原生API被删除以供弃用,我没有设法找到替代它们的替代解决方案.我是一名C++开发人员,在java方面经验不足.我现在用的是原生API是:JVM_LoadClass0,JVM_AllocateNewObject和JVM_AllocateNewArray.
我在Java中的源代码是:
protected Class resolveClass(MercObjectStreamClass v) throws IOException, ClassNotFoundException
{
/* Resolve by looking up the stack for a non-zero class
* loader. If not found use the system loader.
*/
String name = v.getName();
try
{
//we are using the loadClass0 method which calls the native JVM_LoadClass0
//JVM_LoadClass0 is deprecated and we need to replace the call
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader == null) {
return loadClass0(null,name);
}
Class scriptCls = loader.loadClass(scriptClassname); …Run Code Online (Sandbox Code Playgroud) I am trying to write a generic function, using template, that is able to return bool, integer or char* or string.
template<typename entryType>
entryType getEntry(xml_node node, const char* entryKey)
{
...
if (is_same<entryType, bool>::value) {
return boolvalue; //returning a boolean
}
else if(is_same<entryType, int>::value) {
return a; //this is an integer
}
else if (is_same<entryType, char*>::value) {
return result; //this is a char*
}
}
Run Code Online (Sandbox Code Playgroud)
and I would like to be able to call it like:
bool bPublisher = getEntry<bool>(node, …Run Code Online (Sandbox Code Playgroud)