Use emoji in Java Variable cause error

I want to use emoji like 😂 in Java variable. I think it is possible but not works.

public class 最大公約数{
  public static void main(String[] args){
    System.out.println("最大公約数 -> " + String.valueOf(最大公約数(Integer.valueOf(args[0]), Integer.valueOf(args[1]))));

  public static int 最大公約数(int a, int 😇){
    if(a%😇 == 0){
      return 😇;
      return 最大公約数(😇, a%😇);

And console:
最大公約数.java:6: error: illegal character: '\ude02' public static int 最大公約数(int 😂, int 😇){ ^ ~~~~~~ 22 errors

Do you know what is wrong?

1 answer

  • answered 2018-03-11 13:34 Emanuel Graf

    I would suggest a workaround with the emoji4j library.


    public void dog(){     
    Emoji class_emoji = EmojiUtils.getEmoji(getClass().getEnclosingClass().getName()).getEmoji();
    //Now you can convert class_emoji  in whatever you want