Given that j.l.r.Method is mutable, the best way to have performance is too 
encapsulate it in a non mutable class, if possible.

As far as i know j.l.r.Method was introduced in Java 1.1 as non mutable and 
become mutable with Java 1.2, (yes, someone seriously fucked up !)
so methods like copyOf were introduced to do defensive copies (the sharing 
mechanism was later introduced, in 1.4, i believe).

cheers,
Rémi

----- Mail original -----
> De: "Kasper Nielsen" <kaspe...@gmail.com>
> À: "core-libs-dev" <core-libs-dev@openjdk.java.net>
> Envoyé: Mercredi 14 Octobre 2015 12:02:01
> Objet: java.lang.reflect.Method.copyOf
> 
> Hi,
> 
> I was wondering if there is any reason for Method.copyOf (and friends)
> being package private.
> 
> I'm trying to make a copy of a large number of Method objects in some
> performance sensitive code to avoid sharing the isAccessible flag.
> 
> And while this is fairly fast.
> 
> Class<?> declaringClass = method.getDeclaringClass();
> try {
>     return declaringClass.getDeclaredMethod(method.getName(),
> method.getParameterTypes());
> } catch (NoSuchMethodException e) {
>     throw new RuntimeException("This should never happen", e);
> }
> 
> I would to like to avoid the performance penalty if possible.
> 
> - Kasper
> 

Reply via email to