How can I pass enum values to a function when using J/Link? What is the correct syntax for typing an enum value?
For example, call normalize()
using NFC
from here.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow can I pass enum values to a function when using J/Link? What is the correct syntax for typing an enum value?
For example, call normalize()
using NFC
from here.
Enumeration value names are accessible using LoadJavaClass
to load the enum class. However, this particular case is complicated by the fact that the enum class Form
is an inner member of the class Normalizer
. To load it, we must reference Form
by its so-called binary name:
LoadJavaClass["java.text.Normalizer$Form"];
Now we can reference the enum values directly in a call to Normalizer.normalize()
:
LoadJavaClass["java.text.Normalizer"];
Normalizer`normalize[
MakeJavaObject@FromCharacterCode[{65, 769}],
Normalizer$Form`NFC] // ToCharacterCode
(* {193} *)