This file contains hidden or 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 Duck: | |
| def quack(self): | |
| print("Quacked") | |
| class AnotherDuck: | |
| def quack(self): | |
| print("Louder Quack") | |
| class Eagle: | |
| def fly(self): |
This file contains hidden or 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 _01_bean; | |
| public class Person { | |
| private final String name; | |
| private final Integer age; | |
| public Person(String name, Integer age) { | |
| this.name = name; | |
| this.age = age; | |
| } |
This file contains hidden or 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 _01_bean | |
| class PersonKT( | |
| val name: String, | |
| val age: Int) |
This file contains hidden or 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(args : Array<String>) { | |
| val person = PersonKT("Jack", 30) | |
| println(person.name) | |
| println(person.age) | |
| } |
This file contains hidden or 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 _02_dataClasses | |
| import org.testng.Assert | |
| fun parseName(name : String): List<String> { | |
| val space = name.indexOf(' ') | |
| return listOf( | |
| name.substring(0, space), | |
| name.substring(space + 1) | |
| ) |
This file contains hidden or 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 _02_dataClasses | |
| import org.testng.Assert | |
| class FullName(val first: String, | |
| val last: String) | |
| fun parseName(name: String): FullName { | |
| val space = name.indexOf(' ') | |
| return FullName( |
This file contains hidden or 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 _03_functions | |
| class StringUtils { | |
| fun getFirstWord(word: String, separator: String): String { | |
| return word.split(separator)[0] | |
| } | |
| fun getFirstWord(word: String) = getFirstWord(word, " ") | |
| } |
This file contains hidden or 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 _03_functions | |
| fun getFirstWord(word: String, separator: String = " "): String { | |
| return word.split(separator)[0] | |
| } | |
| fun main() { | |
| val first = getFirstWord("Jane Doe") | |
| println("First word: $first") |
This file contains hidden or 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 _03_functions | |
| fun String.getFirstWord(separator: String = " "): String { | |
| return this.split(separator)[0] | |
| } | |
| fun main() { | |
| val first = "Jane Doe".getFirstWord() | |
| println("First word: $first") |
This file contains hidden or 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 _03_functions | |
| fun String.getFirstWord(separator: String = " "): String { | |
| return this.split(separator)[0] | |
| } | |
| // Example of extension properties | |
| // In this case on top of a String class | |
| val String.lastWord: String |
OlderNewer