Created
October 4, 2018 06:02
-
-
Save dgreenhalgh/70e63dcd410b11974ff5d9a5e821b77b to your computer and use it in GitHub Desktop.
Big Nerd Ranch Java Interoperability
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("Hero") | |
import java.io.IOException | |
fun main(args: Array<String>) { | |
val adversary = Jhava() | |
println(adversary.utterGreeting()) | |
val friendshipLevel = adversary.determineFriendshipLevel() | |
println(friendshipLevel?.toLowerCase() ?: "It's complicated.") | |
val adversaryHitPoints: Int = adversary.hitPoints | |
println(adversaryHitPoints.dec()) | |
println(adversaryHitPoints.javaClass) | |
adversary.greeting = "Hello, Hero." | |
println(adversary.utterGreeting()) | |
adversary.offerFood() | |
try { | |
adversary.extendHandInFriendship() | |
} catch (e: Exception) { | |
println("Begone, foul beast!") | |
} | |
adversary.apologize() | |
} | |
val translator = { utterance: String -> | |
println(utterance.toLowerCase().capitalize()) | |
} | |
fun makeProclamation() = "Greetings, beast!" | |
@JvmOverloads | |
fun handOverFood(leftHand: String = "berries", rightHand: String = "beef") { | |
println("Mmmm... you hand over some delicious $leftHand and $rightHand.") | |
} | |
@Throws(IOException::class) | |
fun acceptApology() { | |
throw IOException() | |
} | |
class Spellbook { | |
@JvmField | |
val spells = listOf("Magic Ms. L", "Lay on Hans") | |
companion object { | |
@JvmField | |
val MAX_SPELL_COUNT = 10 | |
@JvmStatic | |
fun getSpellbookGreeting() = println("I am the Great Grimoire!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment