{"can't serve $snack!"} println("$snack is served") } } fun addItemTo(ref: Refreshments<Snack>) = println("item added") val refreshments: Refreshments<TimTam> = Refreshments(TimTam()) addItemTo(refreshments) Type mismatch: inferred type is Refreshments<TimTam> but Refreshments<Snack> was expected 81
{ check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } Type parameter T is declared as 'out' but occurs in 'invariant' position in type Container<T> 113
{ val snackBrother: T = container.spillSnack() check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } interface Container<T: Snack> { fun contain(snack: T) fun spillSnack(): T } 118
{ val snackBrother: T = container.spillSnack() check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } interface Container<T: Snack> { fun contain(snack: T) fun spillSnack(): T } 119
{ val snackBrother: T = container.spillSnack() check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } interface Container<T: Snack> { fun contain(snack: T) fun spillSnack(): T } Snack 120
{ val snackBrother: T = container.spillSnack() check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } interface Container<T: Snack> { fun contain(snack: T) fun spillSnack(): T } 121
{ val snackBrother: T = container.spillSnack() check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } interface Container<out T: Snack> { fun contain(snack: T) fun spillSnack(): T } 122
{ val snackBrother: T = container.spillSnack() check(!snack.needsContainer) {"can't serve $snack!"} println("$snack is served") } } interface Container<out T: Snack> { fun contain(snack: T) fun spillSnack(): T } Type parameter T is declared as 'out' but occurs in 'in' position in type Container<T> 123
type - type parameters that only ever occur in return values of functions, or on val properties. • In type - type parameters that only ever occur as an argument to functions. 132
hasRefreshmentOfType() = snack is R //.. } inline reified Generic types are normally only available at compile time, and get replaced with the actual types. 163
important, so we'll pass it to the constructor. private String owner; private String branch; private double balance; private double interestRate; public Builder(long accountNumber) { this.accountNumber = accountNumber; } public Builder withOwner(String owner){ this.owner = owner; return this; //By returning the builder each time, we can create a fluent interface. } public Builder atBranch(String branch){ this.branch = branch; return this; } public Builder openingBalance(double balance){ this.balance = balance; return this; } public Builder atRate(double interestRate){ this.interestRate = interestRate; return this; } public BankAccount build(){ //Here we create the actual bank account object, which is always in a fully initialised state when it's returned. BankAccount account = new BankAccount(); //Since the builder is in the BankAccount class, we can invoke its private constructor. account.accountNumber = this.accountNumber; 279
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 338
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 339
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 340
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 341
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 342
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 343
// Java - Decompiler public final class MyClass { @NotNull private final String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 344
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 345
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 346
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 347
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 348
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 349
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 350
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 351
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 352
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 353
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 354
// Java - Decompiler public final class MyClass { @NotNull private String text = "Hello world"; @NotNull public final String getText() { return this.text; } public final void setText(@NotNull String var1) { Intrinsics.checkParameterIsNotNull(var1, "<set-?>"); this.text = var1; } } 355
default returns from the nearest enclosing function or anonymous function. • break - Terminates the nearest enclosing loop. • continue - Proceeds to the next step of the nearest enclosing loop. 458
y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 503
y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 504
y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 505
y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 506
(Int, Int) -> Int = { x, y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 507
(Int, Int) -> Int = { x, y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 508
(Int, Int) -> Int = { x, y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 509
IntOperation = { x, y -> x + y } val sub: (Int, Int) -> Int = { x, y -> x - y } val multiply: (Int, Int) -> Int = { x, y -> x * y } Val diff: (Int, Int) -> Int = { x, y -> x / y } 510
IntOperation = { x, y -> x + y } val sub: IntOperation = { x, y -> x - y } val multiply: IntOperation = { x, y -> x * y } Val diff: IntOperation = { x, y -> x / y } 511