< prev index next >

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

Print this page

417      * different interfaces.
418      */
419     private static void collectCompatibleTypes(Class<?>[] from,
420                                                Class<?>[] with,
421                                                List<Class<?>> list) {
422         for (Class<?> fc : from) {
423             if (!list.contains(fc)) {
424                 for (Class<?> wc : with) {
425                     if (wc.isAssignableFrom(fc)) {
426                         list.add(fc);
427                         break;
428                     }
429                 }
430             }
431         }
432     }
433 
434     /**
435      * Generate a class file for the proxy class.  This method drives the
436      * class file generation process.






437      */
438     private byte[] generateClassFile() {
439         /*
440          * Add proxy methods for the hashCode, equals,
441          * and toString methods of java.lang.Object.  This is done before
442          * the methods from the proxy interfaces so that the methods from
443          * java.lang.Object take precedence over duplicate methods in the
444          * proxy interfaces.
445          */
446         addProxyMethod(new ProxyMethod(OBJECT_HASH_CODE_METHOD, OBJECT_HASH_CODE_SIG, "m0"));
447         addProxyMethod(new ProxyMethod(OBJECT_EQUALS_METHOD, OBJECT_EQUALS_SIG, "m1"));
448         addProxyMethod(new ProxyMethod(OBJECT_TO_STRING_METHOD, OBJECT_TO_STRING_SIG, "m2"));
449 
450         /*
451          * Accumulate all of the methods from the proxy interfaces.
452          */
453         for (Class<?> intf : interfaces) {
454             for (Method m : intf.getMethods()) {
455                 if (!Modifier.isStatic(m.getModifiers())) {
456                     addProxyMethod(m, intf);

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