Skip to content

Instantly share code, notes, and snippets.

@lukaspili
Created April 12, 2012 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaspili/2367803 to your computer and use it in GitHub Desktop.
Save lukaspili/2367803 to your computer and use it in GitHub Desktop.
/**
* @author Lukasz Piliszczuk <lukasz.pili AT gmail.com>
*/
public class Main {
public static void main(String... args) {
Character character1 = new Character();
character1.hp = 100;
Character character2 = character1;
character2.hp = 300;
System.out.println(character1.hp); // 300
System.out.println(character2.hp); // 300
}
}
class Character {
int hp;
}
/**
* @author Lukasz Piliszczuk <lukasz.pili AT gmail.com>
*/
public class Main {
public static void main(String... args) {
Character character1 = new Character();
character1.hp = 100;
setTo300(character1);
System.out.println(character1.hp); // 300
}
public static void setTo300(Character character) {
character.hp = 300;
}
}
class Character {
int hp;
}
/**
* @author Lukasz Piliszczuk <lukasz.pili AT gmail.com>
*/
public class Main {
public static void main(String... args) {
Character character1 = new Character();
character1.hp = 100;
setTo300(character1);
System.out.println(character1.hp);
}
public static void setTo300(Character character) {
character = new Character();
character.hp = 300;
}
}
class Character {
int hp;
}
/**
* @author Lukasz Piliszczuk <lukasz.pili AT gmail.com>
*/
public class Main {
public static void main(String... args) {
int i = 1000, j = 1000;
System.out.println(i == j); // true
Integer v = 1000;
Integer w = 1000;
System.out.println(v == w); // false
System.out.println(v.equals(w)); // true
v = 500; // new Integer(500)
w = 500; // new Integer(500)
System.out.println(v == w); // false
v = 127; // new Integer(100)
w = 127; // w = v
System.out.println(v == w); // true
System.out.println(v.equals(w));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment