Skip to content

Instantly share code, notes, and snippets.

@afsinka
Last active Aug 30, 2018
Embed
What would you like to do?
package com;
public class Main {
public static void main(String[] args) {
MyString myString = new MyString("x");
String str = "x";
System.out.println("1: " + myString.getName() + " " + str);
foo(myString, str);
System.out.println("@important 3: " + myString.getName() + " " + str);
// reset
myString = new MyString("x");
str = new String("x");
System.out.println("4: " + myString.getName() + " " + str);
fee(myString, str);
System.out.println("@important 6: " + myString.getName() + " " + str);
String str2 = str;
str2 += "*SPOILED*";
System.out.println("7: " + str + " " + str2);
}
public static void foo(MyString myString, String str) {
myString.setName("y");
str = "y";
System.out.println("2: " + myString.getName() + " " + str);
}
public static void fee(MyString myString, String str) {
myString = new MyString("y");
str = new String("y");
System.out.println("5: " + myString.getName() + " " + str);
}
}
class MyString {
private String name;
public MyString(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment