Skip to content

Instantly share code, notes, and snippets.

@jeffypooo
Created October 13, 2019 22:19
Show Gist options
  • Save jeffypooo/04a8bc29210e995ceb5ddbc51902cdb7 to your computer and use it in GitHub Desktop.
Save jeffypooo/04a8bc29210e995ceb5ddbc51902cdb7 to your computer and use it in GitHub Desktop.
Misc utilities similar to Kotlin stdlib require funcs
package com.beartooth.relaytestapp.util
import java.lang.ref.WeakReference
/**
* Require.kt
* author: jefferson jones
* org: Beartooth, Inc
* github: github.com/masterjefferson
* email: jeff@beartooth.com
*/
fun <T: Any> requireReference(weakRef: WeakReference<T>, message: String? = null): T {
message ?: return requireNotNull(weakRef.get())
return requireNotNull(weakRef.get()) { message }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment