Weitere ähnliche Inhalte Ähnlich wie Kotlin Presentation (20) Kürzlich hochgeladen (20) Kotlin Presentation2. • What is Kotlin
• Why Kotlin
• Write some code
4. • New statically-typed programming language from JetBrains
• Runs on the JVM
• Start from 2010
• Open sourced in February 2012,
• Kotlin v1.0 was released on February 15, 2016
• At Google I/O 2017, Google announced first-class support for Kotlin on Android
What is Kotlin
6. • Focused on interoperability with Java
• Concise
• Target platforms: server-side, Android, anywhere Java runs
• Functional and object-oriented
Why Kotlin
• Pragmatic
7. view.setOnClickListener { }
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Kotlin:
Java:
data class Contact(var name: String, var lastName: String, var age: Int)
class Contact {
private String name;
private String lastName;
private String age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Contact contact = (Contact) o;
if (name != null ? !name.equals(contact.name) : contact.name != null) return false;
if (lastName != null ? !lastName.equals(contact.lastName) : contact.lastName != null)
return false;
return age != null ? age.equals(contact.age) : contact.age == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
result = 31 * result + (age != null ? age.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Contact{" +
"name='" + name + ''' +
", lastName='" + lastName + ''' +
", age='" + age + ''' +
'}';
}
}
Kotlin:
Java: