Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/security/GuardedObject#pubctors) \| [Methods](https://developer.android.com/reference/java/security/GuardedObject#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/security/GuardedObject#inhmethods)

# GuardedObject

` public class GuardedObject `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Serializable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.security.GuardedObject |

<br />

*** ** * ** ***

A GuardedObject is an object that is used to protect access to another object.

A GuardedObject encapsulates a target object and a Guard object, such that access to the target object is possible only if the Guard object allows it. Once an object is encapsulated by a GuardedObject, access to that object is controlled by the `getObject` method, which invokes the `checkGuard` method on the Guard object that is guarding access. If access is not allowed, an exception is thrown.
**See also:**

- `https://developer.android.com/reference/java/security/Guard`
- `https://developer.android.com/reference/java/security/Permission`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/security/GuardedObject#GuardedObject(java.lang.Object,%20java.security.Guard)(https://developer.android.com/reference/java/lang/Object object, https://developer.android.com/reference/java/security/Guard guard) ` Constructs a GuardedObject using the specified object and guard. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/security/GuardedObject#getObject()() ` Retrieves the guarded object, or throws an exception if access to the guarded object is denied by the guard. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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

### GuardedObject

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

```
public GuardedObject (Object object, 
                Guard guard)
```

Constructs a GuardedObject using the specified object and guard. If the Guard object is null, then no restrictions will be placed on who can access the object.

<br />

| Parameters ||
|---|---|
| `object` | `Object`: the object to be guarded. <br /> |
| `guard` | `Guard`: the Guard object that guards access to the object. <br /> |

## Public methods

### getObject

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

```
public Object getObject ()
```

Retrieves the guarded object, or throws an exception if access to the guarded object is denied by the guard.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | the guarded object. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if access to the guarded object is denied. |