# Tutorial: implementing native methods **WARNING:** This support is not yet implemented. Duchess also supports implementing Java native methods, making it easy to call Rust code from Java. ## Setup Be sure to follow the [setup instructions](./setup.md). ## Example Given a Java class ```java package me.ferris; public class ClassWithNativeMethod { int data() { return 22; } native String compute(Object o); } ``` you can provide an implementation for `compute` like so: ```rust,ignore // First, reflect the class, as described in the "calling Java from Rust" tutorial: duchess::java_package! { package me.ferris; class ClassWithNativeMethod { * } } use duchess::{java, IntoJava}; use me::ferris::ClassWithNativeMethod; // Next, provide a decorated Rust function. // The arguments are translated from Java, including the `this`. // The return type is either a scalar or `impl IntoJava` // where `J` is the Java type. #[duchess::native(me.ferris.ClassWithNativeMethod::compute)] fn compute( this: &ClassWithNativeMethod, object: &java::lang::Object, ) -> impl IntoJava { // in here you can call back to JVM too let data = this.data().execute(); format!("Hello from Rust {data}") } ```