JavaClassWrapper

package
v0.0.0-...-fa94a0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

The JavaClassWrapper singleton provides a way for the Godot application to send and receive data through the Java Native Interface (JNI).

Note: This singleton is only available in Android builds.

package main

import (
	"fmt"

	"graphics.gd/classdb/JavaClassWrapper"
	"graphics.gd/variant/Object"
)

func ExampleJavaClassWrapper() {
	var LocalDateTime = JavaClassWrapper.Wrap("java.time.LocalDateTime")
	var DateTimeFormatter = JavaClassWrapper.Wrap("java.time.format.DateTimeFormatter")
	var datetime = Object.Call(LocalDateTime, "now")
	var formatter = Object.Call(DateTimeFormatter, "ofPattern", "dd-MM-yyyy HH:mm:ss")
	fmt.Println(Object.Call(datetime.(Object.Instance), "format", formatter))
}

Warning: When calling Java methods, be sure to check JavaClassWrapper.GetException to check if the method threw an exception.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func GetException

func GetException() JavaObject.Instance

Returns the Java exception from the last call into a Java class. If there was no exception, it will return null.

Note: This method only works on Android. On every other platform, this method will always return null.

func Wrap

func Wrap(name string) JavaClass.Instance

Wraps a class defined in Java, and returns it as a JavaClass Object type that Godot can interact with.

When wrapping inner (nested) classes, use $ instead of . to separate them. For example, JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams") wraps the WindowManager.LayoutParams class.

Note: To invoke a constructor, call a method with the same name as the class. For example:

Note: This method only works on Android. On every other platform, this method does nothing and returns an empty JavaClass.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.JavaClassWrapper

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL