< prev index next >

src/java.base/share/classes/java/lang/reflect/Executable.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -133,21 +133,34 @@
      * Generate toString header information specific to a method or
      * constructor.
      */
     abstract void specificToStringHeader(StringBuilder sb);
 
+    String typeVarBounds(TypeVariable<?> typeVar) {
+        Type[] bounds = typeVar.getBounds();
+        if (bounds.length == 1 && bounds[0].equals(Object.class)) {
+            return typeVar.getName();
+        } else {
+            StringJoiner sj = new StringJoiner(" & ");
+            for (Type bound : bounds) {
+                sj.add(bound.getTypeName());
+            }
+            return typeVar.getName() + " extends " + sj.toString();
+        }
+    }
+
     String sharedToGenericString(int modifierMask, boolean isDefault) {
         try {
             StringBuilder sb = new StringBuilder();
 
             printModifiersIfNonzero(sb, modifierMask, isDefault);
 
             TypeVariable<?>[] typeparms = getTypeParameters();
             if (typeparms.length > 0) {
                 StringJoiner sj = new StringJoiner(",", "<", "> ");
                 for(TypeVariable<?> typeparm: typeparms) {
-                    sj.add(typeparm.getTypeName());
+                    sj.add(typeVarBounds(typeparm));
                 }
                 sb.append(sj.toString());
             }
 
             specificToGenericStringHeader(sb);
< prev index next >