Uploaded image for project: 'yangtools'
  1. yangtools
  2. YANGTOOLS-866

ClassLoaderUtils.withClassLoader is hard to use in Java 8 with Supplier as well as Callable signatures

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Medium
    • Resolution: Done
    • None
    • 2.0.3
    • None
    • None

    Description

      https://git.opendaylight.org/gerrit/#/c/68840/ pointed to 
      yangtools.util.ClassLoaderUtils's{{withClassLoader(...)}}, but this method is hard to use in practice with Java 8 lambdas (perhaps it was written before Java 8) because it has overloaded Supplier as well as Callable signatures, therefore e.g. something like this:

      ClassLoaderUtils.withClassLoader(KarafIniWebEnvironment.class.getClassLoader(), () -> {
       return factory.getInstance();
      });
      

       
      fails with:

      The method withClassLoader(ClassLoader, Supplier<SecurityManager>) is ambiguous for the type ClassLoaderUtils

      this can be worked around with a cast like this of course, but this is cumbersome:

      ClassLoaderUtils.withClassLoader(
                      KarafIniWebEnvironment.class.getClassLoader(), (Supplier<SecurityManager>) factory::getInstance);
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            rovarga Robert Varga
            vorburger Michael Vorburger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: