< prev index next >

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

Print this page

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






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

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