# BoundaryInterfaceReflectionUtil

# BoundaryInterfaceReflectionUtil

Artifact:[androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit)  
[View Source](https://cs.android.com/search?q=file:org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java+class:org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil)  

<br />

```
public class BoundaryInterfaceReflectionUtil
```

<br />

*** ** * ** ***

A set of utility methods used for calling across the support library boundary.

## Summary

|                                                                                 ### Public constructors                                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [BoundaryInterfaceReflectionUtil](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#BoundaryInterfaceReflectionUtil())`()` |

|                                                                                         ### Public methods                                                                                         |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `static @`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` T`                                                                                                     | `<T> `[castToSuppLibClass](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#castToSuppLibClass(java.lang.Class<T>,java.lang.reflect.InvocationHandler))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T> clazz,` ` @`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)` invocationHandler` `)` Returns an implementation of the boundary interface named clazz, by delegating method calls to the[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)invocationHandler. |
| `static boolean`                                                                                                                                                                                   | [containsFeature](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#containsFeature(java.lang.String[],java.lang.String))`(String[] features, `[String](https://developer.android.com/reference/java/lang/String.html)` soughtFeature)`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `static boolean`                                                                                                                                                                                   | [containsFeature](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#containsFeature(java.util.Collection<java.lang.String>,java.lang.String))`(`[Collection](https://developer.android.com/reference/java/util/Collection.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`> features, `[String](https://developer.android.com/reference/java/lang/String.html)` soughtFeature)` Check whether a set of features {@param features} contains a certain feature {@param \* soughtFeature}.                                                                                                                                                                                                                                                           |
| `static @`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html) | `@`[RequiresApi](https://developer.android.com/reference/androidx/annotation/RequiresApi)`(value = Build.VERSION_CODES.KITKAT)` [createInvocationHandlerFor](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlerFor(java.lang.Object))`(@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[Object](https://developer.android.com/reference/java/lang/Object.html)` delegate)` Create an[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)that delegates method calls to`delegate`, making sure that the[Method](https://developer.android.com/reference/java/lang/reflect/Method.html)and parameters being passed exist in the same as`delegate`.                     |
| `static @`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` InvocationHandler[]`                                                                                   | `@`[RequiresApi](https://developer.android.com/reference/androidx/annotation/RequiresApi)`(value = Build.VERSION_CODES.KITKAT)` [createInvocationHandlersForArray](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlersForArray(java.lang.Object[]))`(@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` Object[] delegates)` Plural version of[createInvocationHandlerFor](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlerFor(java.lang.Object)).                                                                                                                                                                                  |
| `static `[Method](https://developer.android.com/reference/java/lang/reflect/Method.html)                                                                                                           | [dupeMethod](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#dupeMethod(java.lang.reflect.Method,java.lang.ClassLoader))`(`[Method](https://developer.android.com/reference/java/lang/reflect/Method.html)` method, `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)` delegateLoader)` Utility method for fetching a method from {@param delegateLoader}, with the same signature (package + class + method name + parameters) as a given method defined in another classloader.                                                                                                                                                                                                                                                              |
| `static @`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[Object](https://developer.android.com/reference/java/lang/Object.html)                               | `@`[RequiresApi](https://developer.android.com/reference/androidx/annotation/RequiresApi)`(value = Build.VERSION_CODES.KITKAT)` [getDelegateFromInvocationHandler](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#getDelegateFromInvocationHandler(java.lang.reflect.InvocationHandler))`(` ` @`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)` invocationHandler` `)` Assuming that the given InvocationHandler was created in the current classloader and is an InvocationHandlerWithDelegateGetter, return the object the InvocationHandler delegates its method calls to.                                                        |
| `static boolean`                                                                                                                                                                                   | [instanceOfInOwnClassLoader](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#instanceOfInOwnClassLoader(java.lang.Object,java.lang.String))`(`[Object](https://developer.android.com/reference/java/lang/Object.html)` obj, `[String](https://developer.android.com/reference/java/lang/String.html)` className)` Check if an object is an instance of`className`, resolving`className`in the object's own ClassLoader.                                                                                                                                                                                                                                                                                                                                                         |

## Public constructors

### BoundaryInterfaceReflectionUtil

```
public BoundaryInterfaceReflectionUtil()
```  

## Public methods

### castToSuppLibClass

```
public static @Nullable T <T> castToSuppLibClass(
    @NonNull Class<T> clazz,
    @Nullable InvocationHandler invocationHandler
)
```

Returns an implementation of the boundary interface named clazz, by delegating method calls to the[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)invocationHandler.

A`null`[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)is treated as representing a`null`object.  

|                                                                                                   Parameters                                                                                                    |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T> clazz`                                            | a[Class](https://developer.android.com/reference/java/lang/Class.html)object representing the desired boundary interface.                       |
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)` invocationHandler` | an[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)compatible with this boundary interface. |

### containsFeature

```
public static boolean containsFeature(String[] features, String soughtFeature)
```  

### containsFeature

```
public static boolean containsFeature(Collection<String> features, String soughtFeature)
```

Check whether a set of features {@param features} contains a certain feature {@param \* soughtFeature}.  

### createInvocationHandlerFor

```
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
public static @Nullable InvocationHandler createInvocationHandlerFor(@Nullable Object delegate)
```

Create an[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)that delegates method calls to`delegate`, making sure that the[Method](https://developer.android.com/reference/java/lang/reflect/Method.html)and parameters being passed exist in the same as`delegate`.

A`null`delegate is represented with a`null`[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html).  

|                                                                                Parameters                                                                                |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[Object](https://developer.android.com/reference/java/lang/Object.html)` delegate` | the object which the resulting[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)should delegate method calls to. |

|                                                                                           Returns                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html) | an InvocationHandlerWithDelegateGetter wrapping`delegate` |

### createInvocationHandlersForArray

```
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
public static @Nullable InvocationHandler[] createInvocationHandlersForArray(@Nullable Object[] delegates)
```

Plural version of[createInvocationHandlerFor](https://developer.android.com/reference/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlerFor(java.lang.Object)). The resulting array will be the same length as`delegates`, where the nth`InvocationHandler`wraps the nth delegate object.

A`null`array of delegates is represented with a`null`array of s. Any individual`null`delegate is represented with a`null`[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html).  

|                                                Parameters                                                |
|----------------------------------------------------------------------------------------------------------|-------------------------------------------|
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` Object[] delegates` | an array of objects to which to delegate. |

|                                                  Returns                                                  |
|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` InvocationHandler[]` | an array of InvocationHandlerWithDelegateGetter instances, each delegating to the corresponding member of`delegates`. |

### dupeMethod

```
public static Method dupeMethod(Method method, ClassLoader delegateLoader)
```

Utility method for fetching a method from {@param delegateLoader}, with the same signature (package + class + method name + parameters) as a given method defined in another classloader.  

|                                                      Throws                                                       |
|-------------------------------------------------------------------------------------------------------------------|---|
| [java.lang.ClassNotFoundException](https://developer.android.com/reference/java/lang/ClassNotFoundException.html) |   |
| [java.lang.NoSuchMethodException](https://developer.android.com/reference/java/lang/NoSuchMethodException.html)   |   |

### getDelegateFromInvocationHandler

```
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
public static @Nullable Object getDelegateFromInvocationHandler(
    @Nullable InvocationHandler invocationHandler
)
```

Assuming that the given InvocationHandler was created in the current classloader and is an InvocationHandlerWithDelegateGetter, return the object the InvocationHandler delegates its method calls to.

A`null`[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)is treated as wrapping a`null`delegate.  

|                                                                                                   Parameters                                                                                                    |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)` invocationHandler` | a[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)InvocationHandlerWithDelegateGetter. |

|                                                                            Returns                                                                            |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| `@`[Nullable](https://developer.android.com/reference/androidx/annotation/Nullable)` `[Object](https://developer.android.com/reference/java/lang/Object.html) | the corresponding delegate. |

### instanceOfInOwnClassLoader

```
public static boolean instanceOfInOwnClassLoader(Object obj, String className)
```

Check if an object is an instance of`className`, resolving`className`in the object's own ClassLoader. This is useful when`obj`may have been created in a ClassLoader other than the current one (in which case`obj instanceof Foo`would fail but`instanceOfInOwnClassLoader(obj, "Foo")`may succeed).