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
// If we use out / in <out T> / <in T> restricts for getter and setter. Also, variance can be used on Classes and Interfaces. | |
abstract class Test<T> { | |
abstract fun getTest(input: T): T | |
} | |
class TestImpAbs : Test<Int>() { | |
override fun getTest(input: Int): Int { | |
return 0 | |
} |
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
//Earlier Approach: | |
// Receiver | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
if(resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE){ | |
val dataStr = data?.getStringExtra("Value") ?:"NO Value" | |
println(dataStr) | |
} | |
} |
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
//Stateful Compose | |
@Composable | |
fun MyCounterStateful() { | |
var vStart by remember { mutableStateOf(5) } | |
var vEnd by remember { mutableStateOf(7) } | |
var noOfTimes by remember { mutableStateOf(0) } | |
ComposePracticesTheme { | |
Column(modifier = Modifier.padding(15.dp)) { | |
Text(text = "Welcome to the Counter") | |
ButtonCounter(noOfTimes) { |
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
@Composable | |
fun MyCounterStateful() { | |
var vStart by remember { mutableStateOf(5) } | |
var vEnd by remember { mutableStateOf(7) } | |
var noOfTimes by remember { mutableStateOf(0) } | |
ComposePracticesTheme { | |
Column(modifier = Modifier.padding(15.dp)) { | |
Text(text = "Welcome to the Counter") | |
Button(onClick = { | |
noOfTimes++ |
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
package delegation | |
fun main() { | |
println(PaymentProcess(CashPayment()).processPayment()) | |
PaymentProcess.isUPIDown = true | |
println(PaymentProcess(UPIPayment("Tez")).processPayment()) | |
PaymentProcess.isUPIDown = false | |
println(PaymentProcess(UPIPayment("Paytm")).processPayment()) | |
PaymentProcess.isCardDown = true | |
println(PaymentProcess(CardPayment("HDFC", "CC")).processPayment()) |
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
package java_comp; | |
class PaymentProcessDelegation { | |
public static void main(String[] args) { | |
new PaymentProcess(new CashPayment()).paymentMode(); | |
System.out.println(new PaymentProcess(new CashPayment()).paymentProcess()); | |
PaymentProcess.isUPIDown = true; | |
System.out.println(new PaymentProcess(new UPIPayment("Tez")).paymentProcess()); | |
PaymentProcess.isUPIDown = false; | |
System.out.println(new PaymentProcess(new UPIPayment("Paytm")).paymentProcess()); |