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 ru.maksim.sample | |
import org.junit.jupiter.api.Test | |
class QuickSort { | |
@Test | |
fun sample() { | |
val a = intArrayOf(3, 5, 2, 8, 6, 4) | |
quickSort(a, 0, a.lastIndex) |
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 ru.maksim.sample | |
inline fun foo(task: () -> Unit) { | |
println("Before task") | |
task() | |
println("After task") | |
} | |
fun callingFunction() { | |
foo { |
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
object ListProcessor { | |
fun processStrings(strings: List<Any>) { | |
Printer.print(strings) | |
} | |
} |
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 Foo<out T : Number>(private val data: T) { | |
fun get2(): T { | |
return data | |
} | |
} | |
class Bar<T>(private val data: T) { | |
fun get2(): T { |
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
interface Source<out T> { | |
fun nextT(): T | |
} | |
class SourceImpl<out T>(private val param: T) : Source<T> { | |
override fun nextT(): T { | |
return param | |
} |
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
interface Consumer<in T> { | |
fun consume(param: T) | |
} | |
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
interface Consumer<in T> { | |
fun put(param: T) | |
} | |
class ConsumerImpl<in T> : Consumer<T> { | |
override fun put(param: T) { | |
println("put param: $param") | |
} |
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 ru.maksim.sample; | |
import org.junit.jupiter.api.Test; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class SampleJavaTest { | |
@Test |
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
// Why are Java generics invariant? | |
// invariant means List<Object> is NOT a parent of List<String>. | |
// if it was the case, then: | |
List<String> strs = new ArrayList<String>(); | |
List<Object> objs = strs; // !!! A compile-time error here saves us from a runtime exception later. | |
objs.add(1); // Put an Integer into a list of Strings | |
String s = strs.get(0); // !!! ClassCastException: Cannot cast Integer to 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
package ru.maksim.sample | |
import org.junit.jupiter.api.Test | |
class ReifiedSampleKotlinTest { | |
@Test | |
fun foo() { | |
val shapeManager = ShapeManager() | |
val circle = Circle(10.0) |
NewerOlder