private static String getSignature(TypeMirror type) {
        StringBuilder sbuf = new StringBuilder();
        type.accept(new SimpleTypeVisitor7<Void, StringBuilder>() {
            @Override
            protected Void defaultAction(TypeMirror e, StringBuilder stringBuilder) {
                return null;
            }

            @Override
            public Void visitPrimitive(PrimitiveType t, StringBuilder stringBuilder) {
                switch (t.getKind()) {
                    case BOOLEAN:
                        stringBuilder.append("Z");
                        break;
                    case BYTE:
                        stringBuilder.append("B");
                        break;
                    case CHAR:
                        stringBuilder.append("C");
                        break;
                    case DOUBLE:
                        stringBuilder.append("D");
                        break;
                    case FLOAT:
                        stringBuilder.append("F");
                        break;
                    case INT:
                        stringBuilder.append("I");
                        break;
                    case LONG:
                        stringBuilder.append("J");
                        break;
                    case SHORT:
                        stringBuilder.append("S");
                        break;
                    default:
                        break;
                }

                return null;
            }

            @Override
            public Void visitArray(ArrayType t, StringBuilder stringBuilder) {
                stringBuilder.append("[");
                t.getComponentType().accept(this, stringBuilder);
                return null;
            }

            @Override
            public Void visitDeclared(DeclaredType t, StringBuilder stringBuilder) {
                stringBuilder.append("L");
                stringBuilder.append(((TypeElement) t.asElement()).getQualifiedName().toString().replace('.', '/'));
                stringBuilder.append(";");

                return null;
            }

            @Override
            public Void visitExecutable(ExecutableType t, StringBuilder stringBuilder) {
                stringBuilder.append("(");
                for (TypeMirror p : t.getParameterTypes()) {
                    p.accept(this, stringBuilder);
                }
                stringBuilder.append(")");
                t.getReturnType().accept(this, stringBuilder);

                return null;
            }

            @Override
            public Void visitNoType(NoType t, StringBuilder stringBuilder) {
                if (t.getKind() == TypeKind.VOID) {
                    stringBuilder.append("V");
                }

                return null;
            }
        }, sbuf);

        return sbuf.toString();
    }
private static String getSignature ( TypeMirror type ) { StringBuilder sbuf = new StringBuilder ( ) ; type . accept ( new SimpleTypeVisitor7 < Void , StringBuilder > ( ) { @ Override protected Void defaultAction ( TypeMirror e , StringBuilder stringBuilder ) { return null ; } @ Override public Void visitPrimitive ( PrimitiveType t , StringBuilder stringBuilder ) { switch ( t . getKind ( ) ) { case BOOLEAN : stringBuilder . append ( "Z" ) ; break ; case BYTE : stringBuilder . append ( "B" ) ; break ; case CHAR : stringBuilder . append ( "C" ) ; break ; case DOUBLE : stringBuilder . append ( "D" ) ; break ; case FLOAT : stringBuilder . append ( "F" ) ; break ; case INT : stringBuilder . append ( "I" ) ; break ; case LONG : stringBuilder . append ( "J" ) ; break ; case SHORT : stringBuilder . append ( "S" ) ; break ; default : break ; } return null ; } @ Override public Void visitArray ( ArrayType t , StringBuilder stringBuilder ) { stringBuilder . append ( "[" ) ; t . getComponentType ( ) . accept ( this , stringBuilder ) ; return null ; } @ Override public Void visitDeclared ( DeclaredType t , StringBuilder stringBuilder ) { stringBuilder . append ( "L" ) ; stringBuilder . append ( ( ( TypeElement ) t . asElement ( ) ) . getQualifiedName ( ) . toString ( ) . replace ( '.' , '/' ) ) ; stringBuilder . append ( ";" ) ; return null ; } @ Override public Void visitExecutable ( ExecutableType t , StringBuilder stringBuilder ) { stringBuilder . append ( "(" ) ; for ( TypeMirror p : t . getParameterTypes ( ) ) { p . accept ( this , stringBuilder ) ; } stringBuilder . append ( ")" ) ; t . getReturnType ( ) . accept ( this , stringBuilder ) ; return null ; } @ Override public Void visitNoType ( NoType t , StringBuilder stringBuilder ) { if ( t . getKind ( ) == TypeKind . VOID ) { stringBuilder . append ( "V" ) ; } return null ; } } , sbuf ) ; return sbuf . toString ( ) ; }
Adapted from {@link java.io.ObjectStreamClass}

<p>Returns JVM type signature for given class.