All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.karlatemp.mxlib.utils.cast.kt Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018-2021 Karlatemp. All rights reserved.
 * @author Karlatemp  
 *
 * MXLib/MXLib.mxlib-api-kotlin.main/cast.kt
 *
 * Use of this source code is governed by the MIT license that can be found via the following link.
 *
 * https://github.com/Karlatemp/MxLib/blob/master/LICENSE
 */

@file:Suppress("NOTHING_TO_INLINE")

package io.github.karlatemp.mxlib.utils

import java.util.*

public inline fun  Any?.castTo(): T = this as T
public inline fun  Any?.safeCast(): T? = this as? T
public inline fun  T?.requireNonNull(): T = this ?: error("null cannot cast to ${T::class.qualifiedName}")
public inline fun  T?.requireNonNull(msg: String): T = this ?: error(msg)
public inline val  Optional.valueOrNull: T? get() = orElse(null)





© 2015 - 2024 Weber Informatics LLC | Privacy Policy