# ConstantCallSite

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#pubctors)\|[Protected Ctors](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#proctors)\|[Methods](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#inhmethods)  

# ConstantCallSite

`
public


class
ConstantCallSite
`  
`


``

extends `[CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite)`


``


`

|---|---|-----------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.lang.invoke.CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite) ||
|   | ↳ | java.lang.invoke.ConstantCallSite |

<br />

*** ** * ** ***

A`ConstantCallSite`is a[CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite)whose target is permanent, and can never be changed. An`invokedynamic`instruction linked to a`ConstantCallSite`is permanently bound to the call site's target.

## Summary

|                                                                                                                                       ### Public constructors                                                                                                                                       ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ConstantCallSite](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#ConstantCallSite(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` target) ` Creates a call site with a permanent target. |

|                                                                                                                                                                                                                              ### Protected constructors                                                                                                                                                                                                                              ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ConstantCallSite](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#ConstantCallSite(java.lang.invoke.MethodType,%20java.lang.invoke.MethodHandle))`(`[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` targetType, `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` createTargetHook) ` Creates a call site with a permanent target, possibly bound to the call site itself. |

|                                                                                                                                                                                                                           ### Public methods                                                                                                                                                                                                                            ||
|------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` final `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[dynamicInvoker](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#dynamicInvoker())`() ` Returns this call site's permanent target.                                                                                                                                                                                                         |
| ` final `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[getTarget](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#getTarget())`() ` Returns the target method of the call site, which behaves like a`final`field of the`ConstantCallSite`.                                                                                                                                                       |
| ` final void`                                                                                  | ` `[setTarget](https://developer.android.com/reference/java/lang/invoke/ConstantCallSite#setTarget(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` ignore) ` Always throws an[UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException). |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.invoke.CallSite](https://developer.android.com/reference/java/lang/invoke/CallSite)` ` |---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[dynamicInvoker](https://developer.android.com/reference/java/lang/invoke/CallSite#dynamicInvoker())`() ` Produces a method handle equivalent to an invokedynamic instruction which has been linked to this call site.                                                                                                                           | | ` abstract `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | ` `[getTarget](https://developer.android.com/reference/java/lang/invoke/CallSite#getTarget())`() ` Returns the target method of the call site, according to the behavior defined by this call site's specific class.                                                                                                                                | | ` abstract void`                                                                                  | ` `[setTarget](https://developer.android.com/reference/java/lang/invoke/CallSite#setTarget(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` newTarget) ` Updates the target method of this call site, according to the behavior defined by this call site's specific class. | | ` `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)              | ` `[type](https://developer.android.com/reference/java/lang/invoke/CallSite#type())`() ` Returns the type of this call site's target.                                                                                                                                                                                                               | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### ConstantCallSite

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

```
public ConstantCallSite (MethodHandle target)
```

Creates a call site with a permanent target.

<br />

|                                          Parameters                                          ||
|----------|------------------------------------------------------------------------------------|
| `target` | `MethodHandle`: the target to be permanently associated with this call site <br /> |

|                                                             Throws                                                             ||
|------------------------------------------------------------------------------------------------|--------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the proposed target is null |

## Protected constructors

### ConstantCallSite

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

```
protected ConstantCallSite (MethodType targetType, 
                MethodHandle createTargetHook)
```

Creates a call site with a permanent target, possibly bound to the call site itself.

During construction of the call site, the`createTargetHook`is invoked to produce the actual target, as if by a call of the form`(MethodHandle) createTargetHook.invoke(this)`.

Note that user code cannot perform such an action directly in a subclass constructor, since the target must be fixed before the`ConstantCallSite`constructor returns.

The hook is said to bind the call site to a target method handle, and a typical action would be`someTarget.bindTo(this)`. However, the hook is free to take any action whatever, including ignoring the call site and returning a constant target.

The result returned by the hook must be a method handle of exactly the same type as the call site.

While the hook is being called, the new`ConstantCallSite`object is in a partially constructed state. In this state, a call to`getTarget`, or any other attempt to use the target, will result in an`IllegalStateException`. It is legal at all times to obtain the call site's type using the`type`method.

<br />

|                                                        Parameters                                                         ||
|--------------------|-------------------------------------------------------------------------------------------------------|
| `targetType`       | `MethodType`: the type of the method handle to be permanently associated with this call site <br />   |
| `createTargetHook` | `MethodHandle`: a method handle to invoke (on the call site) to produce the call site's target <br /> |

|                                                                                                                    Throws                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| [WrongMethodTypeException](https://developer.android.com/reference/java/lang/invoke/WrongMethodTypeException) | if the hook cannot be invoked on the required arguments, or if the target returned by the hook is not of the given`targetType` |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)                | if the hook returns a null value                                                                                               |
| [ClassCastException](https://developer.android.com/reference/java/lang/ClassCastException)                    | if the hook returns something other than a`MethodHandle`                                                                       |
| [Throwable](https://developer.android.com/reference/java/lang/Throwable)                                      | anything else thrown by the hook function                                                                                      |

## Public methods

### dynamicInvoker

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

```
public final MethodHandle dynamicInvoker ()
```

Returns this call site's permanent target. Since that target will never change, this is a correct implementation of[CallSite.dynamicInvoker](https://developer.android.com/reference/java/lang/invoke/CallSite#dynamicInvoker()).

<br />

|                                                                                Returns                                                                                ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the immutable linkage state of this call site, a constant method handle <br /> |

|                                                                         Throws                                                                          ||
|--------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the`ConstantCallSite`constructor has not completed |

### getTarget

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

```
public final MethodHandle getTarget ()
```

Returns the target method of the call site, which behaves like a`final`field of the`ConstantCallSite`. That is, the target is always the original value passed to the constructor call which created this instance.

<br />

|                                                                                Returns                                                                                ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the immutable linkage state of this call site, a constant method handle <br /> |

|                                                                         Throws                                                                          ||
|--------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the`ConstantCallSite`constructor has not completed |

### setTarget

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

```
public final void setTarget (MethodHandle ignore)
```

Always throws an[UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException). This kind of call site cannot change its target.

<br />

|                                         Parameters                                         ||
|----------|----------------------------------------------------------------------------------|
| `ignore` | `MethodHandle`: a new target proposed for the call site, which is ignored <br /> |

|                                                                                  Throws                                                                                   ||
|------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| [UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException) | because this kind of call site cannot change its target |