# NavDestination.Companion

Artifact: [androidx.navigation:navigation-common](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/NavDestination.+class:androidx.navigation.NavDestination.Companion) Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

*** ** * ** ***


```
public static class NavDestination.Companion
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.sequences/-sequence/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavDestination>` | `https://developer.android.com/reference/androidx/navigation/NavDestination#(androidx.navigation.NavDestination).getHierarchy()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavDestination receiver)` Provides a sequence of the NavDestination's hierarchy. |
| `static final boolean` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/navigation/NavDestination#(androidx.navigation.NavDestination).hasRoute()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavDestination receiver)` Checks if the NavDestination's `https://developer.android.com/reference/androidx/navigation/NavDestination#route()` was generated from `https://developer.android.com/reference/androidx/navigation/NavDestination.Companion#(androidx.navigation.NavDestination).hasRoute()` |
| `static final boolean` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/navigation/NavDestination#(androidx.navigation.NavDestination).hasRoute(kotlin.reflect.KClass)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavDestination receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> route )` Checks if the NavDestination's route was generated from `https://developer.android.com/reference/androidx/navigation/NavDestination.Companion#(androidx.navigation.NavDestination).hasRoute(kotlin.reflect.KClass)` |

| ### Protected methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<C>` | `<C extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/navigation/NavDestination#parseClassFromName(android.content.Context,kotlin.String,java.lang.Class)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<C> expectedClassType )` Parse the class associated with this destination from a raw name, generally extracted from the `android:name` attribute added to the destination's XML. |

## Public methods

### getHierarchy

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public static final @NonNull Sequence<@NonNull NavDestination> getHierarchy(@NonNull NavDestination receiver)
```

Provides a sequence of the NavDestination's hierarchy. The hierarchy starts with this destination itself and is then followed by this destination's `https://developer.android.com/reference/androidx/navigation/NavDestination#parent()`, then that graph's parent, and up the hierarchy until you've reached the root navigation graph.

### hasRoute

```
public static final boolean <T extends Object> hasRoute(@NonNull NavDestination receiver)
```

Checks if the NavDestination's `https://developer.android.com/reference/androidx/navigation/NavDestination#route()` was generated from `https://developer.android.com/reference/androidx/navigation/NavDestination.Companion#(androidx.navigation.NavDestination).hasRoute()`

Returns true if equal, false otherwise.

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | the route from KClass |

### hasRoute

Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.8.0)

```
public static final boolean <T extends Object> hasRoute(
    @NonNull NavDestination receiver,
    @NonNull KClass<@NonNull T> route
)
```

Checks if the NavDestination's route was generated from `https://developer.android.com/reference/androidx/navigation/NavDestination.Companion#(androidx.navigation.NavDestination).hasRoute(kotlin.reflect.KClass)`

Returns true if equal, false otherwise.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> route` | the route from KClass |

## Protected methods

### parseClassFromName

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
protected static final @NonNull Class<C> <C extends Object> parseClassFromName(
    @NonNull Context context,
    @NonNull String name,
    @NonNull Class<C> expectedClassType
)
```

Parse the class associated with this destination from a raw name, generally extracted from the `android:name` attribute added to the destination's XML. This should be the class providing the visual representation of the destination that the user sees after navigating to this destination.

This method does name -\> Class caching and should be strongly preferred over doing your own parsing if your `https://developer.android.com/reference/androidx/navigation/Navigator` supports the `android:name` attribute to give consistent behavior across all Navigators.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | Context providing the package name for use with relative class names and the ClassLoader |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name` | Absolute or relative class name. Null names will be ignored. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<C> expectedClassType` | The expected class type |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<C>` | The parsed class |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the class is not found in the provided Context's ClassLoader or if the class is not of the expected type |