Created
December 25, 2014 19:11
-
-
Save nazarov-yuriy/149853ce4f2021689778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.*; | |
public class NameOfDemo { | |
public MyString getName() { | |
if(fake){ | |
return (new MyString(this.name){}); | |
}else{ | |
return this.name; | |
} | |
} | |
public void setName(MyString name) { | |
this.name = name; | |
} | |
public MyString name; | |
public boolean fake; | |
//Fake constructor | |
public NameOfDemo() { | |
fake = true; | |
name = new MyString(""); | |
} | |
//Real constructor | |
public NameOfDemo(String val) { | |
fake = false; | |
name = new MyString(val); | |
} | |
public static String nameof(MyString val){ | |
return val.getClass().getEnclosingMethod().getName().replace("get", "").toLowerCase(); | |
} | |
public static void main(String[] args) { | |
System.out.println( nameof((new NameOfDemo()).getName()) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment