class ref

Use (conceptually) non-owning type ref when type of reference (local, global or weak global) doesn’t matter. Use local_ref, global_ref or weak_ref explicitly to specify owning semantics. For example, use global_ref or weak_ref to store a reference in your C++ object when returning control to Java.

#include <scapix/jaba_api/java/lang/String.h>

using namespace scapix::link::java;
using namespace scapix::java_api;

void test()
    // canonical form:
    auto s = java::lang::String::new_object();

    // same as:
    ref<java::lang::String> s = java::lang::String::new_object();

    // effectively same as:
    local_ref<java::lang::String> s = java::lang::String::new_object();

    // create global reference from returned local reference:
    global_ref<java::lang::String> s = java::lang::String::new_object();

    // create weak global reference from returned local reference:
    weak_ref<java::lang::String> s = java::lang::String::new_object();

While ref is conceptually a non-owning type, it is actually implemented to take ownership when moved to, and not to take ownership when copied to. This allows both zero overhead parameters (copy) and safe return of temporaries (move).