Nestor Morenobetter up and coming artist drops his newest release

Morenobetter known as Incognito is a Latin American youthful civic music songster and rapper, This talented artist has demonstrated his passion in the assiduity indeed though he has a veritably short…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Kotlin and You

If you are in android application development and haven’t heard of Kotlin, you must be from another planet. But if you’ve heard about it and still wondering what it is all about, do read on.

Kotlin is a statically typed programming language with some really unique and awesome features such as non-nullability, high order functions etc. that are supposed to make the life of developers much easier. Kotlin has gained so much popularity in its small span of time. Kotlin is being positioned as the SWIFT for android application development. Kotlin may do to Java; what SWIFT did to Objective C.

In Google’s recent annual developers meetup known as Google IO, Google announced its official support for Kotlin to develop android applications. It is not that Kotlin was not used for android development earlier. A league of developers have been using it and raising their voices to make it an official one. Now that is it officially announced, “Kotlin” is the most talked about word these days in android community.

Kotlin was developed by JetBrains which is coincidentally responsible for developing the IntelliJ Idea platform on which the android studio, the official IDE for android development, is based.

One might be thinking that why are people going crazy about Kotlin? Well, there are reasons worthy of such response from developers. I spent a few days exploring the awesome and unique features of Kotlin and I would suggest you to explore it first hand to get a better context.

For invoking your excitement to dive into it, I’ll list down some features of Kotlin that make it the language it is.

Yeah, you read it Right. Kotlin has its variable declaration syntax defined in such a way that you can decide which variable can hold null values and which can not. In case, if you assign a potential null value to a not-null variable, it will be caught at compilation time itself. Thus a not-null variable will never have a null value at runtime, So no NPEs. Cool, isn’t it? So following declaration and assignment of variable “str” will give compile time error:
var str : String = “abc”<br /><br />
a = null // compilation error

If you want a variable to hold null value you can define it like this:
var b : String? = “abc”<br /><br />
b = null // ok

2. Smart cast

It is the feature that you always wanted to have in your development with Java. This feature allows you to check the type of a variable then perform operation on it according to its type. For example, if the datatype of a variable is String it will allow operations defined on a String object and on the same object if it detects it is an Integer then it will allow operations done on Integer.How do we do that? Just use an operator “is” to check for the type.
val n:Any = "Hello"<br /><br />
when(n) {<br /><br />
is String -> n.length<br /><br />
is Int -> n.inc()<br /><br />
}

3. High Order Functions

Long gone are days when function could just take data types as their parameters, as the high order functions are here. High order function are those functions which can take another function as parameters. This is another feature that we missed so much in Java.
fun logExecution(func: () -> Unit) {<br /><br />
Log.d("tag", "before executing func")<br /><br />
func()<br /><br />
Log.d("tag", "after executing func")<br /><br />
}

4. Default and named arguments
Absence of this feature in Java makes the developer to add function overloading concept as all parameters declared has to be passed by the caller but with this feature you can get rid of all these just by giving the default value to the parameter whom you want to make optional while calling that method. With named argument now you can easily change the sequence of the parameter at the time of calling this is done by writing the name of the argument and then assigning the value to it. For example a function like the following:
fun awesomeFunction(num: Int, str: String = "Kotlin") { }
All of the following are valid :
awesomeFunction(45, " Kotlin is pretty good")<br /><br />
awesomeFunction(str = " i am a fan now", num = 25) //Named argument<br /><br />
awesomeFunction(95) //usage of default argument

Along with above features there are few others as well, like, Data Classes that remove the need of making POJOs, Multi-value return from function, Extension functions etc.. Oh No, did i forgot to mention that with Kotlin you do not need to use findViewById() anymore? Kotlin extensions do it for you. You can perform operations directly on IDs defined in your xml files. There You Go !

This is the one very question that every android application developer has in mind now. I think the answer is pretty simple, change is the only constant. With the list of amazing features that Kotlin has, one would eventually have to move on from Java. For now, one should start writing codes in Kotlin as well in their respective projects. Java will come to your rescue if you get stuck with syntax or anything because Kotlin supports full Java interoperability (another great thing). Kotlin will save one from writing a lot of boilerplate code that we all hate to write. Just give it a try, you’ll love it.

I am listing a few resources here, just in case you feel lost in google search results:

Add a comment

Related posts:

How to grid search a neural network

There are many different ways to build a neural network to achieve different means. These are all different ways to stratify your layers in order to achieve your desired results. There are a lot…

9 Signs You Sell cbg tincture for a Living

Table of ContentsThc Free Bulk Cbg Isolate Fundamentals ExplainedThe Single Strategy To Use For Cbg Cannabigerol IsolateHow Thc Free Bulk Cbg Isolate can Save You Time, Stress, and Money.All about…

Welcome to Axo

We have been blown away by the support for the Maladex protocol and vision of a fair, transparent, and efficient financial system for all. We’re doing all we can to deliver you the future of finance…