[YANGTOOLS-866] ClassLoaderUtils.withClassLoader is hard to use in Java 8 with Supplier as well as Callable signatures Created: 16/Mar/18  Updated: 19/Mar/18  Resolved: 19/Mar/18

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.3

Type: Improvement Priority: Medium
Reporter: Michael Vorburger Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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);


 Comments   
Comment by Robert Varga [ 19/Mar/18 ]

https://git.opendaylight.org/gerrit/69608

 

Generated at Wed Feb 07 20:54:32 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.