This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Top-level | |
class Args(val key: String) { | |
inline operator fun <reified T> getValue(thisRef: Fragment, property: KProperty<*>): T { | |
return checkNotNull(thisRef.arguments).get(key) as T | |
} | |
} | |
//Usage | |
fragment.arguments = Bundle().apply { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.reflect.KProperty | |
class Example { | |
// var p: String by Delegate() | |
override fun toString() = "Example Class" | |
} | |
class Example2 { | |
val p :String? by Delegate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
想做的事情是 "API callback"的統一處理,外部傳入的Callback型態可能跟Retrofit的不同或是相同 | |
做一個Wrapper,可以自己判斷若相同型態時就直接pass by, 若不同則使用外部傳入的transformer | |
private inline fun <reified T, reified R> wrap(noinline successListener: (Int, R) -> Unit, | |
noinline failureListener:(error: Throwable)->Unit, | |
noinline transformer:((T?)->R)? = null):Callback<T>{ | |
return BaseResponseWrapper(successListener,failureListener){t: T? -> | |
return@BaseResponseWrapper if(transformer!=null) transformer(t) else defaultTransformer(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<iframe src="https://drive.google.com/file/d/1JhYDR2xW5wVafjphQobVlPbL9ts_Yo-G/preview" width="640" height="480"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.map { name -> Timber.d("1 $name" +Thread.interrupted()); | |
Thread.sleep(1000); | |
Timber.d("1- $name" +Thread.interrupted());name | |
} | |
.map { name -> Timber.d("2 $name" +Thread.interrupted()); | |
Thread.sleep(1000); | |
Timber.d("2- $name" +Thread.interrupted());name } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
... | |
buildTypes { | |
... | |
debug{ | |
multiDexEnabled true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Logger.d("BUG", "Death!!") | |
when(try{ null } catch (e:Exception) { -1 }){ | |
in 0..Int.MAX_VALUE -> 1 | |
else -> -1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BST::TreeNode::TreeNode(const int& v):data(v){}; | |
//Driver | |
void BST::insert(const int& val){ | |
insert(val,root); | |
print(); | |
} | |
//Workhorse | |
void BST::insert(const int& val, BST::TreeNode* &node){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Workhorse | |
BST::TreeNode* BST::minElement(const int& threshold, BST::TreeNode* &node){ | |
if(node == NULL){ | |
return NULL; | |
} | |
if(node->sum < threshold){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestVolatile { | |
volatile private boolean v = true; | |
private boolean n = true; | |
void invokeLoop(final boolean isVolatile){ | |
Thread t = new Thread(){ | |
@Override | |
public void run(){ | |
while(true){ |