Skip to content

Compile fixes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kotlin-examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/kotlin-runtime.jar
libraries/runtime.xml
libraries/runtime.xml
out/
4 changes: 2 additions & 2 deletions kotlin-examples/src/_01_beans/KotlinBeans.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun main(args: Array<String>) {



val users = arrayList(john, jane, poss)
val users = arrayListOf(john, jane, poss)

for (user in users) {
println(user)
Expand All @@ -51,7 +51,7 @@ fun main(args: Array<String>) {



val byNickName = hashMap(
val byNickName = hashMapOf(
"Johny" to john,
"Jan" to jane,
"Boo" to poss
Expand Down
4 changes: 2 additions & 2 deletions kotlin-examples/src/_02_extensions/Filter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun main(args : Array<String>) {



println("${over30.size()} user(s) over 30 years old")
println("${over30.size} user(s) over 30 years old")



Expand All @@ -41,7 +41,7 @@ fun main(args : Array<String>) {



val youngestOver20 = users filter {u -> u.age > 20 } min {a, b -> a.age - b.age}
val youngestOver20 = users.filter {u -> u.age > 20 }.min {a, b -> a.age - b.age}
println("Youngest over 20: $youngestOver20")
}

Expand Down
4 changes: 2 additions & 2 deletions kotlin-examples/src/_02_extensions/MultiDecl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fun main(args : Array<String>) {
// testIndexedIteration()
}

fun Point.component1() = x
fun Point.component2() = y
operator fun Point.component1() = x
operator fun Point.component2() = y



Expand Down
2 changes: 1 addition & 1 deletion kotlin-examples/src/_02_extensions/StringIterator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun main(args : Array<String>) {



fun String.iterator() = StringIterator(this)
operator fun String.iterator() = StringIterator(this)

class StringIterator(val str: String): Iterator<Char> {

Expand Down
14 changes: 7 additions & 7 deletions kotlin-examples/src/_02_extensions/guava.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.google.common.base.Function
import com.google.common.base.Predicate

fun main(args: Array<String>) {
val list = arrayList("a", "bb", "acc")
val list = arrayListOf("a", "bb", "acc")



Expand Down Expand Up @@ -37,21 +37,21 @@ fun main(args: Array<String>) {

}

fun p<T>(body: (T) -> Boolean): Predicate<T>
fun <T : Any> p(body: (T) -> Boolean): Predicate<T>
= object : Predicate<T> {
public override fun apply(p0: T): Boolean {
return body(p0)
public override fun apply(p0: T?): Boolean {
return body(checkNotNull(p0))
}

public override fun equals(p0: Any?): Boolean {
throw UnsupportedOperationException()
}
}

fun gf<T>(body: (String) -> T): Function<String, T>
fun <T> gf(body: (String) -> T): Function<String, T>
= object : Function<String, T> {
public override fun apply(p0: String): T {
return body(p0)
public override fun apply(p0: String?): T {
return body(checkNotNull(p0))
}
public override fun equals(p0: Any?): Boolean {
throw UnsupportedOperationException()
Expand Down
2 changes: 1 addition & 1 deletion kotlin-examples/src/_02_extensions/loopWithIndex.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package _02_extensions.loopWithIndex

fun main(args: Array<String>) {
val list = arrayList("a", "b", "c")
val list = arrayListOf("a", "b", "c")
list.loopWithIndex({i, v -> println("list[$i] = $v")})
}

Expand Down
4 changes: 2 additions & 2 deletions kotlin-examples/src/_03_swing/SwingBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ var JFrame.size : Pair<Int, Int>
get() = Pair(getSize().getWidth().toInt(), getSize().getHeight().toInt())
set(dim) {setSize(Dimension(dim.first, dim.second))}

var JFrame.height : Int
var JFrame.heightInt : Int
get() = getSize().getHeight().toInt()
set(h) {setSize(width, h)}

var JFrame.width : Int
var JFrame.widthInt : Int
get() = getSize().getWidth().toInt()
set(w) {setSize(height, w)}

Expand Down
4 changes: 2 additions & 2 deletions kotlin-examples/src/_03_swing/SwingDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ val greeting = "Hello,\n\nEnter some text here!"

fun main(args : Array<String>) {
JFrame("Demo") {
height = 400
width = 400
heightInt = 400
widthInt = 400

val text = JTextArea(greeting)
center = text
Expand Down
6 changes: 3 additions & 3 deletions kotlin-examples/src/_03_swing/html/html.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import javax.swing.JScrollPane
import java.util.ArrayList

class Attribute(val name : String, val value : String) {
fun toString() = """$name="$value" """
override fun toString() = """$name="$value" """
}

abstract class Tag(val name : String) {
val children : MutableList<Tag> = ArrayList()
val attributes : MutableList<Attribute> = ArrayList()
open fun toString() = "<$name${attributes.join(prep = " ")}>${children.join()}</$name>"
override fun toString() = "<$name${attributes.join(prep = " ")}>${children.join()}</$name>"
}

class HTML : Tag("html")
Expand All @@ -29,7 +29,7 @@ class Text(val text : String) : Tag("b") {
override fun toString() = text
}

fun Tag.doInit<T : Tag>(t : T, f : T.() -> Unit) : T{
fun <T : Tag> Tag.doInit(t : T, f : T.() -> Unit) : T{
t.f()
children.add(t)
return t
Expand Down
2 changes: 1 addition & 1 deletion kotlin-examples/src/_05_nulls/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ fun main(args : Array<String>) {
println(files?.size ?: "no files")
}

fun fail() = throw IllegalArgumentException()
fun fail(): Nothing = throw IllegalArgumentException()
3 changes: 2 additions & 1 deletion kotlin-examples/src/_07_annotations/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import org.junit.Test as test
import org.junit.Assert.*

class Tests {
test fun simple() {
@test
fun simple() {
assertEquals(4, 2 * 2)
}
}
2 changes: 1 addition & 1 deletion kotlin-examples/src/_08_collections/collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fun print(list: List<Any>) {
}

fun main(args: Array<String>) {
val l: ArrayList<Int> = arrayList(1, 2, 3)
val l: ArrayList<Int> = arrayListOf(1, 2, 3)

print(l)
}