1
1
Fork 0

Removed sections

This commit is contained in:
Svetlana Isakova 2019-10-10 17:46:18 +02:00
parent 61f064151b
commit 7ca2f8dcee
81 changed files with 0 additions and 993 deletions

View File

@ -1,8 +0,0 @@
// Erasure/ErasedTypeEquivalence.kt
import atomictest.eq
fun main() {
val c1 = listOf<String>()::class
val c2 = listOf<Int>()::class
c1 eq c2
}

View File

@ -1,22 +0,0 @@
// Erasure/TypeOfT.kt
package generics
import atomictest.eq
fun <T> typeOfT(arg: T) =
"$arg: " + when(arg) {
is Car -> "Car"
is Int -> "Int"
is String -> "String"
else -> "${(arg?:"")::class}"
}
data class Alien(
val n:String = "Pibbles")
fun main() {
typeOfT(Car()) eq "Car(name=Car): Car"
typeOfT(1) eq "1: Int"
typeOfT("Morty") eq "Morty: String"
typeOfT(Alien()) eq
"Alien(n=Pibbles): class generics.Alien"
}

View File

@ -1,6 +0,0 @@
type: theory
files:
- name: src/ErasedTypeEquivalence.kt
visible: true
- name: src/TypeOfT.kt
visible: true

View File

@ -1,3 +0,0 @@
## Erasure & Reification
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,30 +0,0 @@
// Reflection/Info.kt
fun info(a: Any) {
val kc = a::class
println("${kc::class}")
kc::class.supertypes.forEach {
println("$it")
}
println("---")
kc::class.members.forEach { println("$it") }
println("===")
println("simpleName: ${kc.simpleName}")
println(
"qualifiedName: ${kc.qualifiedName}")
println("Constructors:")
kc.constructors.forEach { println("$it") }
println("Members:")
kc.members.forEach { println(" $it") }
println("Super Types:")
kc.supertypes.forEach { println(" $it") }
println("isData: ${kc.isData}")
}
data class Baz(val i: Int, val s: String) {
constructor(): this(11, "Joy")
}
fun main() {
info(Baz(1, "Happy"))
}

View File

@ -1,5 +0,0 @@
// Reflection/Name.kt
package reflection
fun className(a: Any): String =
a::class.simpleName ?: ""

View File

@ -1,17 +0,0 @@
// Reflection/Solid.kt
import atomictest.eq
import reflection.className
class Solid {
override fun toString() = className(this)
}
class Solid2(val size: Int) {
override fun toString() =
"${className(this)}($size)"
}
fun main() {
Solid() eq "Solid"
Solid2(47) eq "Solid2(47)"
}

View File

@ -1,8 +0,0 @@
type: theory
files:
- name: src/Name.kt
visible: true
- name: src/Solid.kt
visible: true
- name: src/Info.kt
visible: true

View File

@ -1,3 +0,0 @@
## Reflection
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,22 +0,0 @@
// Variance/Bird.kt
package variance
import atomictest.eq
open class Bird
open class Duck: Bird()
class Mallard: Duck()
open class MakeBird {
open fun make(): Bird = Bird()
}
fun test(maker: MakeBird, result: String) {
val bird = maker.make()
val name = bird::class.simpleName ?: ""
name eq result
}
fun main() {
test(MakeBird(), "Bird")
val b: Bird = MakeBird().make()
}

View File

@ -1,28 +0,0 @@
// Variance/Contravariance.kt
package variance
import atomictest.eq
open class Base {
open fun f(b: Mallard) = "Base::f"
}
open class Derived: Base() {
/* override */ fun f(b: Duck) =
"Derived::f"
}
class Derived2: Derived() {
/* override */ fun f(b: Bird) =
"Derived2::f"
}
fun main() {
Derived2().f(Mallard()) eq "Base::f"
Derived2().f(Duck()) eq "Derived::f"
Derived2().f(Bird()) eq "Derived2::f"
Derived().f(Mallard()) eq "Base::f"
Derived().f(Duck()) eq "Derived::f"
Base().f(Mallard()) eq "Base::f"
}

View File

@ -1,29 +0,0 @@
// Variance/CovariantReturnTypes.kt
package variance
open class MakeDuck2: MakeBird() {
override fun make(): Duck = Duck()
}
class MakeMallard2: MakeDuck2() {
override fun make(): Mallard = Mallard()
}
class Bicycle
class MakeBicycle: MakeBird() {
// Fails:
// override fun make(): Bicycle = Bicycle()
val errorMessage = """
Return type of 'make' is not a subtype of
the return type of the overridden member
'public open fun make(): Bird'
"""
}
fun main() {
test(MakeDuck2(), "Duck")
test(MakeMallard2(), "Mallard")
val d: Duck = MakeDuck2().make()
val m: Mallard = MakeMallard2().make()
}

View File

@ -1,18 +0,0 @@
// Variance/SameReturnTypes.kt
package variance
open class MakeDuck1: MakeBird() {
override fun make(): Bird = Duck()
}
class MakeMallard1: MakeDuck1() {
override fun make(): Bird = Mallard()
}
fun main() {
test(MakeDuck1(), "Duck")
test(MakeMallard1(), "Mallard")
val d: Duck = MakeDuck1().make() as Duck
val m: Mallard =
MakeMallard1().make() as Mallard
}

View File

@ -1,10 +0,0 @@
type: theory
files:
- name: src/Bird.kt
visible: true
- name: src/SameReturnTypes.kt
visible: true
- name: src/CovariantReturnTypes.kt
visible: true
- name: src/Contravariance.kt
visible: true

View File

@ -1,3 +0,0 @@
## Variance & Star Projections
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,4 +0,0 @@
content:
- Variance & Star Projections
- Erasure & Reification
- Reflection

View File

@ -1,41 +0,0 @@
// Coroutines/CompareDelayingTask.kt
import atomictest.eq
import kotlinx.coroutines.*
import kotlin.system.measureTimeMillis
suspend fun task(): Int {
delay(1000L) // Performing work...
return 111 // Result of work
}
fun sequentialTasks() = runBlocking<Double> {
measureTimeMillis {
val result =
List(5) { task() }.sumBy { it }
result eq 555
}.toDouble()
}
fun parallelTasks() = runBlocking<Double> {
measureTimeMillis {
val result =
List(5) { async { task() } }
.sumBy { it.await() }
result eq 555
}.toDouble()
}
// Simple round to two decimal places:
fun round2dp(d: Double) =
Math.round(d * 100) / 100.0
fun main() {
val seq = sequentialTasks()
val par = parallelTasks()
println("Ratio: ${round2dp(seq / par)}")
}
/* Sample output:
555
555
Ratio: 4.88
*/

View File

@ -1,53 +0,0 @@
// Coroutines/CompareSlowFib.kt
import bigint.*
import kotlinx.coroutines.*
import kotlin.system.measureTimeMillis
// Slow Fibonacci function:
fun fibs(n: BigInt): BigInt {
assert(n >= zero)
return when (n) {
zero -> zero
one -> one
else -> fibs(n - one) + fibs(n - two)
}
}
fun sequentialFibs(): Double {
val results = Array<BigInt>(3, { zero })
return measureTimeMillis {
results[0] = fibs(36.big)
results[1] = fibs(37.big)
results[2] = fibs(38.big)
}.toDouble()
}
fun parallelFibs() = runBlocking<Double> {
val results = Array<BigInt>(3, { zero })
measureTimeMillis {
val a = launch {
results[0] = fibs(36.big)
}
val b = launch {
results[1] = fibs(37.big)
}
val c = launch {
results[2] = fibs(38.big)
}
a.join()
b.join()
c.join()
}.toDouble()
}
fun main() {
val seq = sequentialFibs()
val par = parallelFibs()
println("Ratio: ${round2dp(seq / par)}")
}
/* Sample output: (2 core machine)
Ratio: 1.68
*/
/* Sample output: (4 core machine)
Ratio: 1.94
*/

View File

@ -1,16 +0,0 @@
// Coroutines/FibonacciSequence.kt
import atomictest.eq
import bigint.*
import kotlin.coroutines.*
fun main() {
val fibonacciSeq = sequence {
var n = Pair(zero, one)
while (true) {
yield(n.first)
n = Pair(n.second, n.first + n.second)
}
}
fibonacciSeq.take(101).last() eq
"354224848179261915075".big
}

View File

@ -1,16 +0,0 @@
// Coroutines/HelloCoroutines.kt
import kotlinx.coroutines.*
fun main() =
runBlocking<Unit> {
val coroutine = launch {
delay(10)
println("Hello,")
}
println("World!")
coroutine.join()
}
/* Output:
World!
Hello,
*/

View File

@ -1,16 +0,0 @@
// Coroutines/LaunchMany.kt
import kotlinx.coroutines.*
fun main() =
runBlocking<Unit> {
val jobs = List(19) {
launch {
delay(1000)
print("$it ")
}
}
jobs.forEach { it.join() }
}
/* Sample output:
6 1 10 7 2 4 9 12 13 14 15 17 16 18 3 0 5 11 8
*/

View File

@ -1,21 +0,0 @@
// Coroutines/LaunchManyTimed.kt
import kotlinx.coroutines.*
import kotlin.system.measureTimeMillis
fun main() =
runBlocking<Unit> {
val duration = measureTimeMillis {
val jobs = List(19) {
launch {
delay(1000)
print("$it ")
}
}
jobs.forEach { it.join() }
}
println("\nDuration: $duration")
}
/* Sample output:
4 6 0 3 1 5 2 8 10 13 14 16 17 18 11 12 7 9 15
Duration: 1020
*/

View File

@ -1,15 +0,0 @@
// Coroutines/LazySequence.kt
import atomictest.eq
import kotlin.coroutines.*
val items = listOf(
1, 19, 34, 22, 97, 11, 72)
fun main() {
val squares = sequence {
for (n in items)
yield(n * n)
}
squares.toList() eq
"[1, 361, 1156, 484, 9409, 121, 5184]"
}

View File

@ -1,16 +0,0 @@
type: theory
files:
- name: src/HelloCoroutines.kt
visible: true
- name: src/LaunchMany.kt
visible: true
- name: src/LaunchManyTimed.kt
visible: true
- name: src/CompareDelayingTask.kt
visible: true
- name: src/CompareSlowFib.kt
visible: true
- name: src/LazySequence.kt
visible: true
- name: src/FibonacciSequence.kt
visible: true

View File

@ -1,3 +0,0 @@
## Coroutines
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,34 +0,0 @@
// asyncandawait/TeaPartyTexting.kt
package asyncandawait
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
fun main() = runBlocking(Dispatchers.Default) {
val marchHare = async {
println("Can you bring the cake?")
delay(3000)
println("Yes, I can bring the cake!")
"cake"
}
val madHatter = async {
println("Can you bring the treacle?")
delay(2000)
println("Yes, I can bring the treacle!")
"treacle"
}
val doorMouse = async {
println("Can you bring the tea?")
delay(1000)
println("Yes, I can bring the tea!")
"tea"
}
println("Alice prepares for the party")
delay(1500)
println("Ready for the party")
println(doorMouse.await())
println(madHatter.await())
println(marchHare.await())
}

View File

@ -1,4 +0,0 @@
type: theory
files:
- name: src/TeaPartyTexting.kt
visible: true

View File

@ -1,3 +0,0 @@
## `async` and `await`
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,3 +0,0 @@
content:
- async and await
- Coroutines

View File

@ -1,14 +0,0 @@
// CollectionsAndJava/CollectionStructure.kt
package collectionsandjava
interface Collection<E>
interface List<E>: Collection<E>
interface Set<E>: Collection<E>
interface Map<K, V>
interface MutableCollection<E>
interface MutableList<E>:
List<E>, MutableCollection<E>
interface MutableSet<E>:
Set<E>, MutableCollection<E>
interface MutableMap<K, V>: Map<K, V>

View File

@ -1,8 +0,0 @@
// CollectionsAndJava/HiddenArrayList.kt
import atomictest.eq
fun main() {
val list = mutableListOf(1, 2, 3)
list.javaClass.name eq
"java.util.ArrayList"
}

View File

@ -1,14 +0,0 @@
// CollectionsAndJava/ImmutableByDefault.kt
package collectionsandjava
data class Animal(val name: String)
interface Zoo {
fun viewAnimals(): Collection<Animal>
}
fun visitZoo(zoo: Zoo) {
val animals = zoo.viewAnimals()
// Compile-time error:
// animals.add(Animal("Grumpy Cat"))
}

View File

@ -1,7 +0,0 @@
// CollectionsAndJava/JavaList.kt
import atomictest.eq
fun main() {
val list = listOf(1, 2, 3)
(list is java.util.List<*>) eq true
}

View File

@ -1,11 +0,0 @@
// CollectionsAndJava/ReadOnlyCollections.kt
import atomictest.eq
fun main() {
val mutableList = mutableListOf(1, 2, 3)
// Read-only reference to a mutable list:
val list: List<Int> = mutableList
mutableList += 4
// list has changed:
list eq "[1, 2, 3, 4]"
}

View File

@ -1,12 +0,0 @@
type: theory
files:
- name: src/HiddenArrayList.kt
visible: true
- name: src/ImmutableByDefault.kt
visible: true
- name: src/CollectionStructure.kt
visible: true
- name: src/JavaList.kt
visible: true
- name: src/ReadOnlyCollections.kt
visible: true

View File

@ -1,3 +0,0 @@
## Collections & Java
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,8 +0,0 @@
// ExceptionHandling/AnnotateThrows.kt
package checked
import java.io.IOException
@Throws(IOException::class)
fun hasCheckedException() {
throw IOException()
}

View File

@ -1,14 +0,0 @@
// ExceptionHandling/CatchChecked.java
import checked.AnnotateThrowsKt;
import java.io.IOException;
import static atomictest.AtomicTestKt.eq;
public class CatchChecked {
public static void main(String[] args) {
try {
AnnotateThrowsKt.hasCheckedException();
} catch(IOException e) {
eq(e, "java.io.IOException");
}
}
}

View File

@ -1,33 +0,0 @@
// ExceptionHandling/JavaChecked.java
import java.io.*;
import java.nio.file.*;
import static atomictest.AtomicTestKt.eq;
public class JavaChecked {
// Build path to current source file, based
// on directory where Gradle is invoked:
static Path thisFile = Paths.get(
"Examples", "ExceptionHandling",
"JavaChecked.java");
public static void main(String[] args) {
BufferedReader source = null;
try {
source = new BufferedReader(
new FileReader(thisFile.toFile()));
} catch(FileNotFoundException e) {
// Recover from file-open error
}
try {
String first = source.readLine();
eq(first, "// ExceptionHandling/" +
"JavaChecked.java");
} catch(IOException e) {
// Recover from read() error
}
try {
source.close();
} catch(IOException e) {
// Recover from close() error
}
}
}

View File

@ -1,10 +0,0 @@
// ExceptionHandling/KotlinChecked.kt
import atomictest.eq
import java.io.File
fun main() {
File("Examples/ExceptionHandling/" +
"KotlinChecked.kt")
.readLines()[0] eq
"// ExceptionHandling/KotlinChecked.kt"
}

View File

@ -1,21 +0,0 @@
// ExceptionHandling/WithCleanup.kt
package withfunction
class Cleanup(n: Int): AutoCloseable {
val id = n
val x = println("Create $id")
fun show() { println("Use $id")}
override fun close() = println("Close $id")
}
fun main() {
with(Cleanup(1)) { show() }
Cleanup(2).use { it.show() }
}
/* Output:
Create 1
Use 1
Create 2
Use 2
Close 2
*/

View File

@ -1,12 +0,0 @@
type: theory
files:
- name: src/ExceptionHandling/JavaChecked.java
visible: true
- name: src/KotlinChecked.kt
visible: true
- name: src/AnnotateThrows.kt
visible: true
- name: src/ExceptionHandling/CatchChecked.java
visible: true
- name: src/WithCleanup.kt
visible: true

View File

@ -1,3 +0,0 @@
## Java Checked Exceptions & Kotlin
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,25 +0,0 @@
// AdaptingJava/BigFibonacci.kt
package adaptingjava
import atomictest.eq
import bigint.*
fun fibonacci(n: Int): BigInt {
tailrec fun fibonacci(
n: Int,
current: BigInt,
next: BigInt
): BigInt {
if (n == 0) return current
return fibonacci(
n - 1, next, current + next)
}
return fibonacci(n, zero, one)
}
fun main() {
(0..7).map { fibonacci(it) } eq
"[0, 1, 1, 2, 3, 5, 8, 13]"
fibonacci(22) eq 17711.big
fibonacci(150) eq
"9969216677189303386214405760200".big
}

View File

@ -1,15 +0,0 @@
// AdaptingJava/BigInt.kt
package bigint
import java.math.BigInteger
typealias BigInt = BigInteger
val Int.big: BigInt
get() = BigInt.valueOf(toLong())
val String.big: BigInt
get() = BigInt(this)
val zero = BigInt.ZERO
val one = BigInt.ONE
val two = 2.big

View File

@ -1,5 +0,0 @@
// fromjava/ChangeName.kt
@file:JvmName("Utils")
package mypackage
fun salad() = "Lettuce!"

View File

@ -1,17 +0,0 @@
// fromkotlin/ExtensionsToJavaClass.kt
package fromkotlin
import atomictest.eq
fun Chameleon.adjustToTemperature(
isHot: Boolean
) {
color = if (isHot) "grey" else "black"
}
fun main() {
val chameleon = Chameleon()
chameleon.size = 2
chameleon.size
chameleon.adjustToTemperature(isHot = true)
chameleon.color eq "grey"
}

View File

@ -1,7 +0,0 @@
// fromjava/KotlinClass.kt
package mypackage
class Basic {
var property1 = 1
fun value() = property1 * 10
}

View File

@ -1,7 +0,0 @@
// fromjava/KotlinDataClass.kt
package fromjava
data class Data(
var name: String,
var age: Int
)

View File

@ -1,8 +0,0 @@
// fromkotlin/Random.kt
import atomictest.eq
import java.util.Random
fun main() {
val rand = Random(47)
rand.nextInt(100) eq 58
}

View File

@ -1,4 +0,0 @@
// fromjava/TopLevelFunction.kt
package mypackage
fun hi() = "Hello!"

View File

@ -1,13 +0,0 @@
// fromkotlin/UseBeanClass.kt
import fromkotlin.Chameleon
import atomictest.eq
fun main() {
val chameleon = Chameleon()
chameleon.size = 1
chameleon.size eq 1
chameleon.color = "green"
chameleon.color eq "green"
chameleon.color = "turquoise"
chameleon.color eq "turquoise"
}

View File

@ -1,10 +0,0 @@
// fromjava/CallTopLevelFunction.java
package fromjava;
import mypackage.TopLevelFunctionKt;
import static atomictest.AtomicTestKt.eq;
public class CallTopLevelFunction {
public static void main(String[] args) {
eq(TopLevelFunctionKt.hi(), "Hello!");
}
}

View File

@ -1,10 +0,0 @@
// fromjava/CallTopLevelFunction2.java
package fromjava;
import static mypackage.TopLevelFunctionKt.hi;
import static atomictest.AtomicTestKt.eq;
public class CallTopLevelFunction2 {
public static void main(String[] args) {
eq(hi(), "Hello!");
}
}

View File

@ -1,10 +0,0 @@
// fromjava/MakeSalad.java
package fromjava;
import mypackage.Utils;
import static atomictest.AtomicTestKt.eq;
public class MakeSalad {
public static void main(String[] args) {
eq(Utils.salad(), "Lettuce!");
}
}

View File

@ -1,24 +0,0 @@
// fromjava/UsingDataClass.java
package fromjava;
import java.util.HashMap;
import static atomictest.AtomicTestKt.eq;
public class UsingDataClass {
public static void main(String[] args) {
Data d = new Data("Alice", 22);
String name = d.getName();
d.setName("Bob");
int age = d.getAge();
d.setAge(age + 1);
// toString():
eq(d, "Data(name=Bob, age=23)");
HashMap<Data, Integer> hm =
new HashMap<>();
hm.put(d, 47);
// Data objects work as hash keys:
eq((double)hm.get(d), (double)47);
// Call copy() from the Data class:
Data d2 = d.copy("Sam", 24);
eq(d2, "Data(name=Sam, age=24)");
}
}

View File

@ -1,13 +0,0 @@
// fromjava/UsingKotlinClass.java
package fromjava;
import mypackage.Basic;
import static atomictest.AtomicTestKt.eq;
public class UsingKotlinClass {
public static void main(String[] args) {
Basic b = new Basic();
eq(b.getProperty1(), 1);
b.setProperty1(12);
eq(b.value(), 120);
}
}

View File

@ -1,21 +0,0 @@
// fromkotlin/Chameleon.java
package fromkotlin;
import java.io.Serializable;
public class
Chameleon implements Serializable {
private int size;
private String color;
public int getSize() {
return size;
}
public void setSize(int newSize) {
size = newSize;
}
public String getColor() {
return color;
}
public void setColor(String newColor) {
color = newColor;
}
}

View File

@ -1,32 +0,0 @@
type: theory
files:
- name: src/Random.kt
visible: true
- name: src/fromkotlin/Chameleon.java
visible: true
- name: src/UseBeanClass.kt
visible: true
- name: src/ExtensionsToJavaClass.kt
visible: true
- name: src/KotlinClass.kt
visible: true
- name: src/fromjava/UsingKotlinClass.java
visible: true
- name: src/KotlinDataClass.kt
visible: true
- name: src/fromjava/UsingDataClass.java
visible: true
- name: src/TopLevelFunction.kt
visible: true
- name: src/fromjava/CallTopLevelFunction.java
visible: true
- name: src/fromjava/CallTopLevelFunction2.java
visible: true
- name: src/ChangeName.kt
visible: true
- name: src/fromjava/MakeSalad.java
visible: true
- name: src/BigInt.kt
visible: true
- name: src/BigFibonacci.kt
visible: true

View File

@ -1,3 +0,0 @@
## Mixing Kotlin & Java
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,20 +0,0 @@
// NullabilityAnnotations/AnnotatedJava.kt
package nullabilityannotations
import javacode.AnnotatedJTool
import atomictest.eq
object KotlinCode {
val a = AnnotatedJTool.getSafe("")
// Won't compile:
// val b = AnnotatedJTool.getSafe(null)
val c = AnnotatedJTool.getUnsafe("")
val d = AnnotatedJTool.getUnsafe(null)
}
fun main() {
with(KotlinCode) {
::a.returnType eq "javacode.JTool"
::c.returnType eq "javacode.JTool?"
::d.returnType eq "javacode.JTool?"
}
}

View File

@ -1,21 +0,0 @@
// javacode/AnnotatedJTool.java
package javacode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class AnnotatedJTool {
@Nullable
public static JTool
getUnsafe(@Nullable String s) {
if(s == null) return null;
return getSafe(s);
}
@NotNull
public static JTool
getSafe(@NotNull String s) {
return new JTool();
}
public String method() {
return "Success";
}
}

View File

@ -1,6 +0,0 @@
type: theory
files:
- name: src/javacode/AnnotatedJTool.java
visible: true
- name: src/AnnotatedJava.kt
visible: true

View File

@ -1,3 +0,0 @@
## Nullability Annotations
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,19 +0,0 @@
// PlatformTypes/NPEOnPlatformType.kt
import javacode.JTool
import atomictest.*
fun main() {
val xn = JTool.get(null) // [1]
xn?.method() eq null // [2]
capture {
xn.method() // [3]
} eq "NullPointerException"
val yn: JTool? = JTool.get(null) // [4]
yn?.method() eq null
capture {
val zn: JTool = JTool.get(null) // [5]
} eq "IllegalStateException: " +
"JTool.get(null) must not be null"
}

View File

@ -1,21 +0,0 @@
// PlatformTypes/PlatformTypes.kt
import javacode.JTool
import atomictest.eq
object KotlinCode {
val a: JTool? = JTool.get("") // [1]
val b: JTool = JTool.get("") // [2]
val c = JTool.get("") // [3]
}
fun main() {
with(KotlinCode) {
a?.method() eq "Success" // [4]
b.method() eq "Success"
c.method() eq "Success" // [5]
::a.returnType eq "javacode.JTool?"
::b.returnType eq "javacode.JTool"
::c.returnType eq
"javacode.JTool!" // [6]
}
}

View File

@ -1,12 +0,0 @@
// javacode/JTool.java
package javacode;
public class JTool {
public static JTool get(String s) {
if(s == null) return null;
return new JTool();
}
public String method() {
return "Success";
}
}

View File

@ -1,8 +0,0 @@
type: theory
files:
- name: src/javacode/JTool.java
visible: true
- name: src/PlatformTypes.kt
visible: true
- name: src/NPEOnPlatformType.kt
visible: true

View File

@ -1,3 +0,0 @@
## Nullable Types & Java
Examples accompanying the atom.

View File

@ -1,2 +0,0 @@
content:
- Examples

View File

@ -1,6 +0,0 @@
content:
- Mixing Kotlin & Java
- Java Checked Exceptions & Kotlin
- Nullable Types & Java
- Nullability Annotations
- Collections & Java

View File

@ -9,7 +9,4 @@ content:
- Functional Programming - Functional Programming
- Object-Oriented Programming - Object-Oriented Programming
- Preventing Failure - Preventing Failure
- Concurrency
- Power Tools - Power Tools
- Advanced Topics
- Language Interoperability