
com.loudsight.utilities.Cast.kt Maven / Gradle / Ivy
The newest version!
package com.loudsight.utilities
/**
* Class to hold utilities related to casting of types
*
* @author munyengm
*/
object Cast {
/**
* Method to cast a given type to an arbitrary type. The small size of the method means it will likely be in-lined
* by the JVM compiler The method is may be used to deal with situations where a warning is produced by the compiler
* stating that a given is an unsafe one i.e. "Type safety: Unchecked cast from O to T" Using this method reduces the
* number of places where the @SuppressWarnings annotation is required and restricts the suppression of warning to this
* method only - ensuring that real warnings aren't inadvertently hidden. The method infers the target type from the
* required return type as illustrated below:
* `
* // Ex.
* T typedObject = Cast.uncheckedCast(object) // where T is the target type
` *
*
* @param object
* @return the typed object
*/
fun uncheckedCast(`object`: Any): T {
return `object` as T
}
// fun uncheckedCast(`object`: Any): T {
// return `object` as T
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy