Search code examples
javacompilationjavac

What is this strange syntax in the package com.sun.tools.javac.code (javac compiler) and how does it work?


I was looking at some of the internal javac sun compiler API source and came across this in the Types class:

public Boolean visitTypeVar(TypeVar var1, Type var2) {
         switch(null.$SwitchMap$com$sun$tools$javac$code$TypeTag[var2.getTag().ordinal()]) {
         case 12:
            if(Types.this.isSubtype(var1, var2)) {
               return Boolean.valueOf(true);
            } else {
               if(Types.this.isCastable(var1.bound, var2, Types.this.noWarnings)) {
                  ((Warner)Types.this.warnStack.head).warn(LintCategory.UNCHECKED);
                  return Boolean.valueOf(true);
               }

               return Boolean.valueOf(false);
            }
         case 13:
         case 16:
            return Boolean.valueOf(true);
         case 14:
         case 15:
         default:
            return Boolean.valueOf(Types.this.isCastable(var1.bound, var2, (Warner)Types.this.warnStack.head));
         }
      }

It's the second line that was interesting at this statement:

null.$SwitchMap$com$sun$tools$javac$code$TypeTag[var2.getTag().ordinal()]

Which looks like it returns an integer. How does this work?


Solution

  • This is just some fancy artifact of your decompiler.

    If you look at the same code in source code form (http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/com/sun/tools/javac/code/Types.java#1658) it is just a switch statement on an enum:

            @Override
            public Boolean visitTypeVar(TypeVar t, Type s) {
                switch (s.tag) {
                case ERROR:
                case BOT:
                    return true;
                case TYPEVAR:
                    if (isSubtype(t, s)) {
                        return true;
                    } else if (isCastable(t.bound, s, Warner.noWarnings)) {
                        warnStack.head.warn(LintCategory.UNCHECKED);
                        return true;
                    } else {
                        return false;
                    }
                default:
                    return isCastable(t.bound, s, warnStack.head);
                }
            }