# 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 />

```
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/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#BoundaryInterfaceReflectionUtil())`()` |

|                                                                                           ### Public functions                                                                                            |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static T?`                                                                                                                                                                                          | `<T> `[castToSuppLibClass](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#castToSuppLibClass(java.lang.Class<T>,java.lang.reflect.InvocationHandler))`(` ` clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>,` ` invocationHandler: `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`?` `)` 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.                                                                            |
| `java-static `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                          | [containsFeature](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#containsFeature(java.lang.String[],java.lang.String))`(features: `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`!>!, soughtFeature: `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`!)`                                                                                                                                                                                                                                                                          |
| `java-static `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                          | [containsFeature](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#containsFeature(java.util.Collection<java.lang.String>,java.lang.String))`(` ` features: (`[Mutable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-collection/index.html)`)`[Collection](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html)`<`[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`!>!,` ` soughtFeature: `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`!` `)` Check whether a set of features {@param features} contains a certain feature {@param \* soughtFeature}. |
| `java-static `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`?`                                                                                    | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = Build.VERSION_CODES.KITKAT)` [createInvocationHandlerFor](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlerFor(java.lang.Object))`(delegate: `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?)` 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`.      |
| `java-static `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`!>?` | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = Build.VERSION_CODES.KITKAT)` [createInvocationHandlersForArray](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlersForArray(java.lang.Object[]))`(delegates: `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`!>?)` Plural version of[createInvocationHandlerFor](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#createInvocationHandlerFor(java.lang.Object)).        |
| `java-static `[Method](https://developer.android.com/reference/java/lang/reflect/Method.html)`!`                                                                                                          | [dupeMethod](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#dupeMethod(java.lang.reflect.Method,java.lang.ClassLoader))`(method: `[Method](https://developer.android.com/reference/java/lang/reflect/Method.html)`!, delegateLoader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`!)` 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.                                                                                                                                                                   |
| `java-static `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?`                                                                                                               | `@`[RequiresApi](https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi)`(value = Build.VERSION_CODES.KITKAT)` [getDelegateFromInvocationHandler](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#getDelegateFromInvocationHandler(java.lang.reflect.InvocationHandler))`(invocationHandler: `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`?)` 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.                                                   |
| `java-static `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                          | [instanceOfInOwnClassLoader](https://developer.android.com/reference/kotlin/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil#instanceOfInOwnClassLoader(java.lang.Object,java.lang.String))`(obj: `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`!, className: `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`!)` Check if an object is an instance of`className`, resolving`className`in the object's own ClassLoader.                                                                                                                                                                                                                                                  |

## Public constructors

### BoundaryInterfaceReflectionUtil

```
BoundaryInterfaceReflectionUtil()
```  

## Public functions

### castToSuppLibClass

```
java-static fun <T> castToSuppLibClass(
    clazz: Class<T!>,
    invocationHandler: InvocationHandler?
): T?
```

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                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>`                                          | a[Class](https://developer.android.com/reference/java/lang/Class.html)object representing the desired boundary interface.                       |
| `invocationHandler: `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`?` | an[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)compatible with this boundary interface. |

### containsFeature

```
java-static fun containsFeature(features: Array<String!>!, soughtFeature: String!): Boolean
```  

### containsFeature

```
java-static fun containsFeature(
    features: (Mutable)Collection<String!>!,
    soughtFeature: String!
): Boolean
```

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

### createInvocationHandlerFor

```
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
java-static fun createInvocationHandlerFor(delegate: Any?): InvocationHandler?
```

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                                         |
|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delegate: `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | the object which the resulting[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)should delegate method calls to. |

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

### createInvocationHandlersForArray

```
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
java-static fun createInvocationHandlersForArray(delegates: Array<Any!>?): Array<InvocationHandler!>?
```

Plural version of[createInvocationHandlerFor](https://developer.android.com/reference/kotlin/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                                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
| `delegates: `[Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`!>?` | an array of objects to which to delegate. |

|                                                                                           Returns                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| [Array](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`!>?` | an array of InvocationHandlerWithDelegateGetter instances, each delegating to the corresponding member of`delegates`. |

### dupeMethod

```
java-static fun dupeMethod(method: Method!, delegateLoader: ClassLoader!): Method!
```

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)
java-static fun getDelegateFromInvocationHandler(invocationHandler: InvocationHandler?): Any?
```

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                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| `invocationHandler: `[InvocationHandler](https://developer.android.com/reference/java/lang/reflect/InvocationHandler.html)`?` | a[Nullable](https://developer.android.com/reference/kotlin/androidx/annotation/Nullable)InvocationHandlerWithDelegateGetter. |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-----------------------------|
| [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?` | the corresponding delegate. |

### instanceOfInOwnClassLoader

```
java-static fun instanceOfInOwnClassLoader(obj: Any!, className: String!): Boolean
```

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