#Control Structures
##If statement
Kotlin if statement should look familiar with other language
fun main(args : Array<String>) {
val total = 10| import java.io.FileInputStream; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.Iterator; | |
| import org.apache.poi.hssf.usermodel.HSSFCell; | |
| import org.apache.poi.hssf.usermodel.HSSFRow; | |
| import org.apache.poi.hssf.usermodel.HSSFSheet; | |
| import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| package pl.kpob.utils.extensions | |
| import android.app.Activity | |
| import android.content.Context | |
| import android.graphics.Color | |
| import android.support.v4.content.ContextCompat | |
| import android.view.WindowManager | |
| import flow.Flow | |
| import org.jetbrains.anko.AlertDialogBuilder | |
| import pl.sisms.gminformix.utils.extensions.supportsLollipop |
| import rx.Observable | |
| import rx.Observer | |
| import rx.Subscriber | |
| import rx.Subscription | |
| import rx.functions.Action0 | |
| import rx.functions.Action1 | |
| fun <T> Observable<T>.uiSubscribe(schedulers: Schedulers, subscriber: Subscriber<in T>): Subscription { | |
| return subscribeOn(schedulers.io) | |
| .observeOn(schedulers.mainThread) |
| apply plugin: 'com.android.application' | |
| apply plugin: 'kotlin-android' | |
| apply plugin: 'me.tatarka.retrolambda' | |
| buildscript { | |
| ext.kotlin_version = '1.0.0-beta-4584' | |
| ext.android_support_lib_version = '23.1.1' | |
| ext.retrolambda_version = '3.2.4' | |
| repositories { | |
| jcenter() |
| fun get(url: String, headers: Headers = Headers()): Observable<Response> { | |
| //return getWithExplicitClass(url, headers)!! | |
| //return getWithAnonymousClass(url, headers)!! | |
| //return getWithInlineUsingObsoleteSubscribeFunc(url, headers)!! | |
| return getWithFailingInlineFunction(url, headers)!! | |
| } | |
| fun getWithFailingInlineFunction(url: String, headers: Headers = Headers()) : Observable<Response>? { | |
| // This fails. Looks like a bug in Kotlin: http://youtrack.jetbrains.com/issue/KT-4598 |
| package actors | |
| import com.google.common.util.concurrent.ListenableFuture | |
| import com.google.common.util.concurrent.SettableFuture | |
| import com.google.common.util.concurrent.MoreExecutors | |
| import java.util.concurrent.Executors | |
| import java.util.ArrayList | |
| import java.util.concurrent.LinkedBlockingQueue | |
| import com.google.common.util.concurrent.ListeningExecutorService | |
| import java.util.concurrent.ThreadFactory |
| open class A { | |
| } | |
| abstract class Adapter<T : A> { | |
| abstract fun create(): T | |
| abstract fun itemCount(): Int | |
| open fun bind(a: T) { | |
| } | |
| } |
| // A couple of inlined utility functions: the first is just a syntax convenience, the second lets us use | |
| // Kotlin's string interpolation efficiently: the message is never calculated/concatenated together unless | |
| // logging at that level is enabled. | |
| inline fun <reified T : Any> loggerFor(): org.slf4j.Logger = LoggerFactory.getLogger(T::class.java) | |
| inline fun org.slf4j.Logger.trace(msg: () -> String) { | |
| if (isTraceEnabled) trace(msg()) | |
| } | |
| /** | |
| * A Java logging formatter that writes more compact output than the default. |
#Control Structures
##If statement
Kotlin if statement should look familiar with other language
fun main(args : Array<String>) {
val total = 10