# DelegateLastClassLoader

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# DelegateLastClassLoader

```
class DelegateLastClassLoader : PathClassLoader
```

|---|---|---|---|--------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                          |||||
| ↳ | [java.lang.ClassLoader](https://developer.android.com/reference/kotlin/java/lang/ClassLoader.html#)                                     ||||
|   | ↳ | [dalvik.system.BaseDexClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/BaseDexClassLoader)                  |||
|   |   | ↳ | [dalvik.system.PathClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/PathClassLoader)                     ||
|   |   |   | ↳ | [dalvik.system.DelegateLastClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#) |

A`ClassLoader`implementation that implements a**delegate last**lookup policy. For every class or resource this loader is requested to load, the following lookup order is employed:

- The boot classpath is always searched first
- Then, the list of`dex`files associated with this classloaders's`dexPath`is searched.
- Finally, this classloader will delegate to the specified`parent`.

<br />

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                          Public constructors                                                                                                                                                                                                                                                                                                                                                                                                                          ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [DelegateLastClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20java.lang.ClassLoader))`(`dexPath:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `parent:` `[ClassLoader](https://developer.android.com/reference/kotlin/java/lang/ClassLoader.html#)!`)` Equivalent to calling[DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean)](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20kotlin.String,%20java.lang.ClassLoader,%20kotlin.Boolean))with`librarySearchPath = null, delegateResourceLoading = true`.                                                                                                  |
| [DelegateLastClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20kotlin.String,%20java.lang.ClassLoader))`(`dexPath:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `librarySearchPath:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `parent:` `[ClassLoader](https://developer.android.com/reference/kotlin/java/lang/ClassLoader.html#)!`)` Equivalent to calling[DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean)](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20kotlin.String,%20java.lang.ClassLoader,%20kotlin.Boolean))with`delegateResourceLoading = true`. |
| [DelegateLastClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20kotlin.String,%20java.lang.ClassLoader,%20kotlin.Boolean))`(`dexPath:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `librarySearchPath:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`, `parent:` `[ClassLoader](https://developer.android.com/reference/kotlin/java/lang/ClassLoader.html#)?`, `delegateResourceLoading:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Creates a`DelegateLastClassLoader`that operates on a given`dexPath`and a`librarySearchPath`.                                                                                                                |

|                                                                                                                                                                                                 Public methods                                                                                                                                                                                                  ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [URL](https://developer.android.com/reference/kotlin/java/net/URL.html#)!                                                                                               | [getResource](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#getResource(kotlin.String))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` <br />   |
| [Enumeration](https://developer.android.com/reference/kotlin/java/util/Enumeration.html#)\<[URL](https://developer.android.com/reference/kotlin/java/net/URL.html#)!\>! | [getResources](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#getResources(kotlin.String))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` <br /> |

|                                                                                                                                                                                                             Protected methods                                                                                                                                                                                                             ||
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Class](https://developer.android.com/reference/kotlin/java/lang/Class.html#)\<\*\>! | [loadClass](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#loadClass(kotlin.String,%20kotlin.Boolean))`(`name:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `resolve:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` <br /> |

## Public constructors

### DelegateLastClassLoader

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
DelegateLastClassLoader(
    dexPath: String!, 
    parent: ClassLoader!)
```

Equivalent to calling[DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean)](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20kotlin.String,%20java.lang.ClassLoader,%20kotlin.Boolean))with`librarySearchPath = null, delegateResourceLoading = true`.  

### DelegateLastClassLoader

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
DelegateLastClassLoader(
    dexPath: String!, 
    librarySearchPath: String!, 
    parent: ClassLoader!)
```

Equivalent to calling[DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean)](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#DelegateLastClassLoader(kotlin.String,%20kotlin.String,%20java.lang.ClassLoader,%20kotlin.Boolean))with`delegateResourceLoading = true`.  

### DelegateLastClassLoader

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
DelegateLastClassLoader(
    dexPath: String, 
    librarySearchPath: String?, 
    parent: ClassLoader?, 
    delegateResourceLoading: Boolean)
```

Creates a`DelegateLastClassLoader`that operates on a given`dexPath`and a`librarySearchPath`. The`dexPath`should consist of one or more of the following, separated by`File.pathSeparator`, which is`":"`on Android.

- JAR/ZIP/APK files, possibly containing a "classes.dex" file as well as arbitrary resources.
- Raw ".dex" files (not inside a zip file).

Unlike[PathClassLoader](https://developer.android.com/reference/kotlin/dalvik/system/PathClassLoader), this classloader will attempt to locate classes (or resources) using the following lookup order.

- The boot classpath is always searched first.
- Then, the list of`dex`files contained in`dexPath`is searched./li\>
- Lastly, this classloader will delegate to the specified`parent`.

Note that this is in contrast to other standard classloaders that follow the delegation model. In those classloaders, the`parent`is always searched first.`librarySearchPath`specifies one more directories containing native library files, separated by`File.pathSeparator`.

<br />

|                                                                                                                               Parameters                                                                                                                                ||
|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dexPath`                 | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the list of jar/apk files containing classes and resources, delimited by`File.pathSeparator`, which defaults to`":"`on Android. This value cannot be`null`. |
| `librarySearchPath`       | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:the list of directories containing native libraries, delimited by`File.pathSeparator`; may be`null`.                                                       |
| `parent`                  | [ClassLoader](https://developer.android.com/reference/kotlin/java/lang/ClassLoader.html#)?:the parent class loader. May be`null`for the boot classloader.                                                                                    |
| `delegateResourceLoading` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):whether to delegate resource loading to the parent if the resource is not found. This does not affect class loading delegation.                           |

## Public methods

### getResource

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getResource(name: String!): URL!
```

|                                                 Parameters                                                  ||
|--------|-----------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The resource name |

|                                                                                                                                                                     Return                                                                                                                                                                     ||
|---------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [URL](https://developer.android.com/reference/kotlin/java/net/URL.html#)! | `URL`object for reading the resource;`null`if the resource could not be found, a`URL`could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager. |

|                     Exceptions                     ||
|----------------------------------|------------------|
| `java.lang.NullPointerException` | If`name`is`null` |

### getResources

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getResources(name: String!): Enumeration<URL!>!
```

|                                                 Parameters                                                  ||
|--------|-----------------------------------------------------------------------------------------------------|
| `name` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The resource name |

|                                                                                                                                                                                                                                                                              Return                                                                                                                                                                                                                                                                              ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Enumeration](https://developer.android.com/reference/kotlin/java/util/Enumeration.html#)<[URL](https://developer.android.com/reference/kotlin/java/net/URL.html#)!>! | An enumeration of[URL](https://developer.android.com/reference/kotlin/java/net/URL.html#)objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which a`URL`cannot be constructed, are in a package that is not opened unconditionally, or access to the resource is denied by the security manager, are not returned in the enumeration. |

|                      Exceptions                       ||
|----------------------------------|---------------------|
| `java.io.IOException`            | If I/O errors occur |
| `java.lang.NullPointerException` | If`name`is`null`    |

## Protected methods

### loadClass

Added in[API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
protected fun loadClass(
    name: String!, 
    resolve: Boolean
): Class<*>!
```

|                                                                                                         Parameters                                                                                                          ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name`    | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:The[binary name](https://developer.android.com/reference/kotlin/dalvik/system/DelegateLastClassLoader#binary-name)of the class |
| `resolve` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html):If`true`then resolve the class                                                                                                |

|                                                    Return                                                     ||
|-----------------------------------------------------------------------------------|----------------------------|
| [Class](https://developer.android.com/reference/kotlin/java/lang/Class.html#)<*>! | The resulting`Class`object |

|                             Exceptions                              ||
|------------------------------------|---------------------------------|
| `java.lang.ClassNotFoundException` | If the class could not be found |