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
/** | |
* This will recover and inject your interface in your fragments or activities | |
*/ | |
inline fun <reified I, reified O> ComponentCallbacks.injectMapper(): Lazy<Mapper<I, O>> { | |
return inject(named(identifier<I, O>())) | |
} |
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
class SampleActivity : AppCompatActivity(R.layout.activity_sample) { | |
private val viewModel by getViewModel { SampleViewModel(SingleLiveEvent()) } | |
... | |
} |
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
fun main() { | |
val descricao = "Inline te dando poderes mágicos" | |
executarOperacao { | |
print(descricao) | |
} | |
} | |
fun executarOperacao(operacaoDois: () -> Unit) { | |
operacaoUm() | |
operacaoDois() |
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 static final void main() { | |
final String descricao = "Inline te dando poderes mágicos"; | |
executarOperacao(new Function() { | |
@Override | |
public void invoke() { | |
System.out.print(descricao); | |
} | |
} | |
} |
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
fun main() { | |
val descricao = "Inline te dando poderes mágicos" | |
val descricaoEmEscopoPrincipal = "Inline no escopo principal" | |
executarOperacao({ | |
print(descricao) | |
return // Retorno permitido | |
}, { | |
print(descricaoEmEscopoPrincipal) | |
return // Retorno não permitido |
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
fun main() { | |
val descricao = "Inline te dando poderes mágicos" | |
executarOperacao { | |
print(descricao) | |
return // Retorno não permitido | |
} | |
} | |
inline fun executarOperacao(crossinline operacaoDois: () -> Unit) { | |
operacaoUm { |
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
fun main() { | |
println(filtrarString(String::class.java)) | |
println(adquirirMetodos(String::class.java)) | |
} | |
fun <T : Any> adquirirMetodos(clazz: Class<T>): List<String> { | |
return clazz::class.java.methods.map { it.toString() } | |
} | |
fun <T : Any> filtrarString(clazz: Class<T>): 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
fun main() { | |
println(filtrarString<String>()) | |
println(adquirirMetodos<String>()) | |
} | |
inline fun <reified T : Any> adquirirMetodos(): List<String> { | |
return T::class.java.methods.map { it.toString() } | |
} |
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 static final void main() { | |
// Função de adquirir métodos | |
Method[] methods = String.class.getMethods(); | |
// Validação da String na lista | |
if (element instanceof String) { | |
// Atribuições | |
} | |
/** |
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
inline fun executarOperacao(crossinline operacaoDois: () -> Unit) { | |
operacaoUm { | |
operacaoDois() | |
} | |
} | |
@PublishedApi | |
internal fun operacaoUm(bloco: () -> Unit) { | |
bloco() | |
} |
OlderNewer