小编ist*_*tik的帖子

使用本机API的替代解决方案:JVM_LoadClass0,JVM_AllocateNewArray和JVM_AllocateNewObject

与Java 9中一样,一些原生API被删除以供弃用,我没有设法找到替代它们的替代解决方案.我是一名C++开发人员,在java方面经验不足.我现在用的是原生API是:JVM_LoadClass0,JVM_AllocateNewObjectJVM_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)

c c++ java jvm java-9

7
推荐指数
1
解决办法
239
查看次数

Return both string and integer from a template function in C++

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)

c++ templates if-statement

3
推荐指数
1
解决办法
1262
查看次数

标签 统计

c++ ×2

c ×1

if-statement ×1

java ×1

java-9 ×1

jvm ×1

templates ×1