Skip to content

Instantly share code, notes, and snippets.

@DevPicon
Last active March 3, 2017 21:24
Show Gist options
  • Save DevPicon/58911d67b05d25106ca3d7699934ce14 to your computer and use it in GitHub Desktop.
Save DevPicon/58911d67b05d25106ca3d7699934ce14 to your computer and use it in GitHub Desktop.
public class Person{
private String name;
private int age;
public Person(String name, String age){
this.name = name;
this.age = age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
}
fun ImageView.loadImage(url: String?){
if(url != null){
Glide.with(this.context)
.load(url)
.fitCenter()
.into(this)
}
}
myImageView.loadImage(“!insert an url here!”)
List people = new ArrayList<Person>();
people.add(new Person(“Armando”,35));
people.add(new Person(“Erik”,26));
people.add(new Person(“Adrian”,30));
forEach(Person person: people){
if(person.getName().equals(“Erik”)){
return person;
}
}
val people = listOf<Person>(Person("Adrian", 30), Person("Erik",26), Person("Armando", 35))
val person = people.find { it.name == "Erik" }
println(person)
val numberList = listOf(1, 2, 3, 4, 5)
val squared = list.map( i -> i * i)
assertTrue(squared.containsAll(listOf(1,4,9,16,25)))
squared.forEach { println(it) }
val numberList = listOf(1, 2, 3, 4, 5)
val squared = list.map( i -> i * i)
assertTrue(squared.containsAll(listOf(1,4,9,16,25)))
squared.forEach { println(it) }
public class MyActivity extends AppCompatActivity{
@Override
public void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.main_activity);
TextView myTextView = (TextView) findViewById(R.id.my_textview);
myTextView.setText(“¡Hola Android!”);
}
}
class MyActivity : AppCompatActivity{
override fun onCreate(saveInstanceState:Bundle){
super.onCreate(saveInstanceState);
setContentView(R.layout.main_activity);
my_textview.text = “¡Hola kotlin!
}
}
class MyActivity : AppCompatActivity{
override fun onCreate(saveInstanceState:Bundle){
super.onCreate(saveInstanceState);
setContentView(R.layout.main_activity);
my_textview.text = “¡Hola kotlin!
}
}
class MyActivity : AppCompatActivity{
override fun onCreate(saveInstanceState:Bundle){
super.onCreate(saveInstanceState);
setContentView(R.layout.main_activity);
val myTextView = findViewById(R.id.my_textview) as TextView;
myTextView.text = “¡Hola kotlin!”}
}
var message : String? = null
fun sayHello(message:String?){
if(message != null){
println(message)
}
}
// Clase declarada por en su forma completa
class Persona constructor(name:String, age: Int){
val name = name
var age = age
}
// Clase simplificada
class Persona(val name: String, var age: Int)
// Data class
data class Persona(val name: String, var age: Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment