Why do classes with underline ("_") in Java become "_1"?

Asked

Viewed 159 times

2

I’m using JNI, using C and Golang, by default we use something like arquivo_windows.go or arquivo_android.go, so I preferred to also call the Java files the same way.

So I created a class named after arquivo_android.java, and the content:

package github.com.inkeliz.arquivo

public class arquivo_android {
}

I don’t know to what extent this is correct in Java, the Java naming convention should be different, but this is not in question.


Here a problem arose when trying to use JNI:

C.FindClass(env.Env, "github/com/inkeliz/arquivo/arquivo_android")

It results in an error, saying that there is no such class. I spent a few hours trying to find out the reason for the error.

Finally, I discovered that, in fact, the correct thing would be to use:

C.FindClass(env.Env, "github/com/inkeliz/arquivo/arquivo_1android")

Using the _1android instead of _android.


I wonder what caused the 1 appear after the _ and what is the rule for this. I wanted to implement a "wrapper" to the C.FindClass(), but already tried to make these substitutions in the name. But, I need to know how and when this occurs.

1 answer

2


JNI follows some rules for concatenating "Dynamic linkers". Then a class with "_" becomes "_1". See the link below for more details:

Resolving Native Method Names

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.