Codota Logo
Method.invoke
Code IndexAdd Codota to your IDE (free)

How to use
invoke
method
in
java.lang.reflect.Method

Best Java code snippets using java.lang.reflect.Method.invoke (Showing top 20 results out of 101,277)

  • Common ways to obtain Method
private void myMethod () {
Method m =
  • Codota IconClass clazz;clazz.getMethod("<changeme>")
  • Codota IconClass clazz;String name;Class[] parameterTypes;clazz.getMethod(name, parameterTypes)
  • Codota IconPropertyDescriptor pd;pd.getReadMethod()
  • Smart code suggestions by Codota
}
origin: square/okhttp

public static void addSuppressedIfPossible(Throwable e, Throwable suppressed) {
 if (addSuppressedExceptionMethod != null) {
  try {
   addSuppressedExceptionMethod.invoke(e, suppressed);
  } catch (InvocationTargetException | IllegalAccessException ignored) {
  }
 }
}
origin: square/okhttp

Object createAndOpen(String closer) {
 if (getMethod != null) {
  try {
   Object closeGuardInstance = getMethod.invoke(null);
   openMethod.invoke(closeGuardInstance, closer);
   return closeGuardInstance;
  } catch (Exception ignored) {
  }
 }
 return null;
}
origin: square/okhttp

boolean warnIfOpen(Object closeGuardInstance) {
 boolean reported = false;
 if (closeGuardInstance != null) {
  try {
   warnIfOpenMethod.invoke(closeGuardInstance);
   reported = true;
  } catch (Exception ignored) {
  }
 }
 return reported;
}
origin: stackoverflow.com

 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
method.setAccessible(true);
return method.invoke(targetObject, argObjects);
origin: square/okhttp

@Override public void afterHandshake(SSLSocket sslSocket) {
 try {
  removeMethod.invoke(null, sslSocket);
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw new AssertionError("failed to remove ALPN", e);
 }
}
origin: square/okhttp

@Override public @Nullable String getSelectedProtocol(SSLSocket socket) {
 try {
  byte[] alpnResult = (byte[]) getAlpnSelectedProtocol.invoke(socket);
  return alpnResult != null ? new String(alpnResult, UTF_8) : null;
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw new AssertionError(e);
 }
}
origin: google/guava

 @Override
 String typeName(Type type) {
  try {
   Method getTypeName = Type.class.getMethod("getTypeName");
   return (String) getTypeName.invoke(type);
  } catch (NoSuchMethodException e) {
   throw new AssertionError("Type.getTypeName should be available in Java 8");
  } catch (InvocationTargetException | IllegalAccessException e) {
   throw new RuntimeException(e);
  }
 }
},
origin: google/guava

private Object invokeGeneratorMethod(Method generator, Object... args) {
 try {
  return generator.invoke(this, args);
 } catch (InvocationTargetException e) {
  throwIfUnchecked(e.getCause());
  throw new RuntimeException(e.getCause());
 } catch (Exception e) {
  throwIfUnchecked(e);
  throw new RuntimeException(e);
 }
}
origin: square/okhttp

private boolean api24IsCleartextTrafficPermitted(String hostname, Class<?> networkPolicyClass,
  Object networkSecurityPolicy) throws InvocationTargetException, IllegalAccessException {
 try {
  Method isCleartextTrafficPermittedMethod = networkPolicyClass
    .getMethod("isCleartextTrafficPermitted", String.class);
  return (boolean) isCleartextTrafficPermittedMethod.invoke(networkSecurityPolicy, hostname);
 } catch (NoSuchMethodException e) {
  return api23IsCleartextTrafficPermitted(hostname, networkPolicyClass, networkSecurityPolicy);
 }
}
origin: square/okhttp

private boolean api23IsCleartextTrafficPermitted(String hostname, Class<?> networkPolicyClass,
  Object networkSecurityPolicy) throws InvocationTargetException, IllegalAccessException {
 try {
  Method isCleartextTrafficPermittedMethod = networkPolicyClass
    .getMethod("isCleartextTrafficPermitted");
  return (boolean) isCleartextTrafficPermittedMethod.invoke(networkSecurityPolicy);
 } catch (NoSuchMethodException e) {
  return super.isCleartextTrafficPermitted(hostname);
 }
}
origin: google/guava

@Override
final Object invokeInternal(@Nullable Object receiver, Object[] args)
  throws InvocationTargetException, IllegalAccessException {
 return method.invoke(receiver, args);
}
origin: google/guava

@GwtIncompatible // java.lang.reflect
private static Object invokeAccessibleNonThrowingMethod(
  Method method, Object receiver, Object... params) {
 try {
  return method.invoke(receiver, params);
 } catch (IllegalAccessException e) {
  throw new RuntimeException(e);
 } catch (InvocationTargetException e) {
  throw propagate(e.getCause());
 }
}
origin: square/okhttp

@Override public boolean isCleartextTrafficPermitted(String hostname) {
 try {
  Class<?> networkPolicyClass = Class.forName("android.security.NetworkSecurityPolicy");
  Method getInstanceMethod = networkPolicyClass.getMethod("getInstance");
  Object networkSecurityPolicy = getInstanceMethod.invoke(null);
  return api24IsCleartextTrafficPermitted(hostname, networkPolicyClass, networkSecurityPolicy);
 } catch (ClassNotFoundException | NoSuchMethodException e) {
  return super.isCleartextTrafficPermitted(hostname);
 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
  throw new AssertionError("unable to determine cleartext support", e);
 }
}
origin: square/okhttp

@Override public void configureTlsExtensions(
  SSLSocket sslSocket, String hostname, List<Protocol> protocols) {
 List<String> names = alpnProtocolNames(protocols);
 try {
  Object alpnProvider = Proxy.newProxyInstance(Platform.class.getClassLoader(),
    new Class[] {clientProviderClass, serverProviderClass}, new AlpnProvider(names));
  putMethod.invoke(null, sslSocket, alpnProvider);
 } catch (InvocationTargetException | IllegalAccessException e) {
  throw new AssertionError("failed to set ALPN", e);
 }
}
origin: google/guava

 private Throwable tryInternalFastPathGetFailure(Future<?> future) throws Exception {
  Method tryInternalFastPathGetFailureMethod =
    abstractFutureClass.getDeclaredMethod("tryInternalFastPathGetFailure");
  tryInternalFastPathGetFailureMethod.setAccessible(true);
  return (Throwable) tryInternalFastPathGetFailureMethod.invoke(future);
 }
}
origin: google/guava

private void runTestMethod(ClassLoader classLoader) throws Exception {
 Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
 Object testInstance = test.newInstance();
 test.getMethod("setUp").invoke(testInstance);
 test.getMethod(getName()).invoke(testInstance);
 test.getMethod("tearDown").invoke(testInstance);
}
origin: square/retrofit

 @Override public Object invoke(Object proxy, Method method, @Nullable Object[] args)
   throws Throwable {
  // If the method is a method from Object then defer to normal invocation.
  if (method.getDeclaringClass() == Object.class) {
   return method.invoke(this, args);
  }
  if (platform.isDefaultMethod(method)) {
   return platform.invokeDefaultMethod(method, service, proxy, args);
  }
  return loadServiceMethod(method).invoke(args != null ? args : emptyArgs);
 }
});
origin: google/guava

private static void doTestMocking(RateLimiter mock) throws Exception {
 for (Method method : RateLimiter.class.getMethods()) {
  if (!isStatic(method.getModifiers())
    && !NOT_WORKING_ON_MOCKS.contains(method.getName())
    && !method.getDeclaringClass().equals(Object.class)) {
   method.invoke(mock, arbitraryParameters(method));
  }
 }
}
origin: google/guava

private Object invokeListMethod(Method method, Object[] args) throws Throwable {
 try {
  Object returnValue = method.invoke(delegate, args);
  mutateDelegate();
  return returnValue;
 } catch (InvocationTargetException e) {
  throw e.getCause();
 } catch (IllegalAccessException e) {
  throw new AssertionError(e);
 }
}
origin: google/guava

@AndroidIncompatible // no FpUtils and no Math.nextDown in old versions
public void testNextDown() throws Exception {
 Method jdkNextDown = getJdkNextDown();
 for (double d : FINITE_DOUBLE_CANDIDATES) {
  assertEquals(jdkNextDown.invoke(null, d), DoubleUtils.nextDown(d));
 }
}
java.lang.reflectMethodinvoke

Javadoc

Invokes the underlying method represented by this Methodobject, on the specified object with the specified parameters. Individual parameters are automatically unwrapped to match primitive formal parameters, and both primitive and reference parameters are subject to method invocation conversions as necessary.

If the underlying method is static, then the specified objargument is ignored. It may be null.

If the number of formal parameters required by the underlying method is 0, the supplied args array may be of length 0 or null.

If the underlying method is an instance method, it is invoked using dynamic method lookup as documented in The Java Language Specification, Second Edition, section 15.12.4.4; in particular, overriding based on the runtime type of the target object will occur.

If the underlying method is static, the class that declared the method is initialized if it has not already been initialized.

If the method completes normally, the value it returns is returned to the caller of invoke; if the value has a primitive type, it is first appropriately wrapped in an object. However, if the value has the type of an array of a primitive type, the elements of the array are not wrapped in objects; in other words, an array of primitive type is returned. If the underlying method return type is void, the invocation returns null.

Popular methods of Method

  • getName
  • getParameterTypes
  • getReturnType
  • setAccessible
  • getDeclaringClass
  • getAnnotation
  • getModifiers
  • isAnnotationPresent
  • getGenericReturnType
    Returns the return type of this method as a Type instance.
  • getParameterAnnotations
  • getGenericParameterTypes
    Returns the parameter types as an array of Type instances, in declaration order. If this method has
  • isAccessible
  • getGenericParameterTypes,
  • isAccessible,
  • equals,
  • getAnnotations,
  • toString,
  • getExceptionTypes,
  • getParameterCount,
  • isBridge,
  • isSynthetic

Popular in Java

  • Finding current android device location
  • compareTo (BigDecimal)
  • findViewById (Activity)
  • putExtra (Intent)
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • ArrayList (java.util)
    Resizable-array implementation of the List interface. Implements all optional list operations, and p
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
  • Timer (java.util)
    A facility for threads to schedule tasks for future execution in a background thread. Tasks may be s
  • TreeMap (java.util)
    A Red-Black tree based NavigableMap implementation. The map is sorted according to the Comparable of
  • JCheckBox (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now