Skip to content

Instantly share code, notes, and snippets.

@nazarov-yuriy
Created December 25, 2014 19:11
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 nazarov-yuriy/149853ce4f2021689778 to your computer and use it in GitHub Desktop.
Save nazarov-yuriy/149853ce4f2021689778 to your computer and use it in GitHub Desktop.
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