Is it possible to send a function(ex: any callback function) as an argument from Java to golang?

My objective: I want to send data from golang to java.

I am using gomobile bind to generate binding for android. I have a use case where I want to write and export a function in golang which takes in a simple function as an argument like so:
func SetCallback(cb Callback)
where Callback is a user defined type:
type Callback func(string)
However gomobile bind is not able to generate java bindings for this function. I have tried to do this directly without defining a Callback type:
func SetCallback(cb func(string))
but no success. Is there any other way to do this?

I think you can’t do that directly. Java and golang has different runtime, their memory layout is also different. Garbage collector in java can’t collect object allocated from Go, it just can’t. They just use different way to do garbage collection. String in java is also different from string in Go. Function in java is also different from function in Go. Their code representation is also different.

But, they do have an FFI for C. Go can call C code (with some adjustment) using CGo, Java can also call C code (again, with some adjustment) with Java JNI. You might be be able to call C from Java, and call Go from that C. But I can be very tricky, hard to debug, and hard to maintain though.