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 TrafficLight.isDrive(): Boolean = when (color) { | |
"green", "yellow" -> true | |
else -> false | |
} |
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 TrafficLightJavaTest { | |
public static void main(String[] args) { | |
TrafficLight trafficLight = new TrafficLight("red"); | |
boolean isDrive = TrafficLightExtensionKt.isDrive(trafficLight); | |
} | |
} |
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
@file:JvmName("TrafficLightUtils") | |
package ... | |
fun TrafficLight.isDrive(): Boolean = when (color) { | |
"green", "yellow" -> true | |
else -> false | |
} |
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 com.kyawhtut.ankotest; | |
public class TrafficLightJavaTest { | |
public static void main(String[] args) { | |
TrafficLight trafficLight = new TrafficLight("red"); | |
boolean isDrive = TrafficLightExtensionKt.isDrive(trafficLight); // this is compile time error | |
boolean isDrive = TrafficLightUtils.isDrive(trafficLight); // this will work | |
} | |
} |
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 Ticket { | |
public final String ticketName; | |
Ticket(String ticketName) { | |
this.ticketName = ticketName; | |
} | |
} |
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
data class Ticket( | |
val ticketName: String | |
) |
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
data class User( | |
var name: String, | |
var age: Int, | |
var address: String = "", | |
var gender: String | |
) |
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 UserTestJava { | |
public static void main(String[] args) { | |
User user = new User("Mg Mg",23, "Yangon", "male"); // that is work | |
User user = new User("Mg Mg",23, "male"); // that is compile time error | |
} | |
} |
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 UserTestKt { | |
val user = User( | |
"Mg Mg", | |
23, | |
gender = "male" | |
) // that is work | |
val user = User( | |
"Mg Mg", | |
23, |
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
data class User @JvmOverloads constructor( | |
var name: String, | |
var age: Int, | |
var address: String = "", | |
var gender: String | |
) |