< prev index next >

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

Print this page

427      * different interfaces.
428      */
429     private static void collectCompatibleTypes(Class<?>[] from,
430                                                Class<?>[] with,
431                                                List<Class<?>> list) {
432         for (Class<?> fc : from) {
433             if (!list.contains(fc)) {
434                 for (Class<?> wc : with) {
435                     if (wc.isAssignableFrom(fc)) {
436                         list.add(fc);
437                         break;
438                     }
439                 }
440             }
441         }
442     }
443 
444     /**
445      * Generate a class file for the proxy class.  This method drives the
446      * class file generation process.






447      */
448     private byte[] generateClassFile() {
449         /*
450          * Add proxy methods for the hashCode, equals,
451          * and toString methods of java.lang.Object.  This is done before
452          * the methods from the proxy interfaces so that the methods from
453          * java.lang.Object take precedence over duplicate methods in the
454          * proxy interfaces.
455          */
456         addProxyMethod(new ProxyMethod(OBJECT_HASH_CODE_METHOD, OBJECT_HASH_CODE_SIG, "m0"));
457         addProxyMethod(new ProxyMethod(OBJECT_EQUALS_METHOD, OBJECT_EQUALS_SIG, "m1"));
458         addProxyMethod(new ProxyMethod(OBJECT_TO_STRING_METHOD, OBJECT_TO_STRING_SIG, "m2"));
459 
460         /*
461          * Accumulate all of the methods from the proxy interfaces.
462          */
463         for (Class<?> intf : interfaces) {
464             for (Method m : intf.getMethods()) {
465                 if (!Modifier.isStatic(m.getModifiers())) {
466                     addProxyMethod(m, intf);

427      * different interfaces.
428      */
429     private static void collectCompatibleTypes(Class<?>[] from,
430                                                Class<?>[] with,
431                                                List<Class<?>> list) {
432         for (Class<?> fc : from) {
433             if (!list.contains(fc)) {
434                 for (Class<?> wc : with) {
435                     if (wc.isAssignableFrom(fc)) {
436                         list.add(fc);
437                         break;
438                     }
439                 }
440             }
441         }
442     }
443 
444     /**
445      * Generate a class file for the proxy class.  This method drives the
446      * class file generation process.
447      *
448      * If a proxy interface references any value classes, the value classes
449      * are listed in the loadable descriptors attribute of the interface class.  The
450      * classes that are referenced by the proxy interface have already
451      * been loaded before the proxy class.  Hence the proxy class is
452      * generated with no loadable descriptors attributes as it essentially has no effect.
453      */
454     private byte[] generateClassFile() {
455         /*
456          * Add proxy methods for the hashCode, equals,
457          * and toString methods of java.lang.Object.  This is done before
458          * the methods from the proxy interfaces so that the methods from
459          * java.lang.Object take precedence over duplicate methods in the
460          * proxy interfaces.
461          */
462         addProxyMethod(new ProxyMethod(OBJECT_HASH_CODE_METHOD, OBJECT_HASH_CODE_SIG, "m0"));
463         addProxyMethod(new ProxyMethod(OBJECT_EQUALS_METHOD, OBJECT_EQUALS_SIG, "m1"));
464         addProxyMethod(new ProxyMethod(OBJECT_TO_STRING_METHOD, OBJECT_TO_STRING_SIG, "m2"));
465 
466         /*
467          * Accumulate all of the methods from the proxy interfaces.
468          */
469         for (Class<?> intf : interfaces) {
470             for (Method m : intf.getMethods()) {
471                 if (!Modifier.isStatic(m.getModifiers())) {
472                     addProxyMethod(m, intf);
< prev index next >