Skip to content

Instantly share code, notes, and snippets.

@edefazio
Last active June 28, 2016 15:04
Show Gist options
  • Save edefazio/d069b76be72ba39f68411fc6e99408c9 to your computer and use it in GitHub Desktop.
Save edefazio/d069b76be72ba39f68411fc6e99408c9 to your computer and use it in GitHub Desktop.
VARCODE Self-Tailoring Java Code
package ex.varcode;
/*{-*/
import io.varcode.tailor.java.JavaCase;
/*-}*/
public class /*{+className*/_1/*+}*/
{
public /*{+className*/_1/*+}*/()
{
System.out.println( /*{+message*/"Hello!"/*+}*/ );
}
/*{-*/
public static void main( String[] args )
{
new _1(); // prints "Hello!"
JavaCase theCase = JavaCase.of(
_1.class,
"className", "TailorMsg",
"message", "Tailored!" );
//tailors java code, compile & create an instance
Object tailored = theCase.instance(); // "Tailored!"
System.out.println(
tailored.getClass().getName() ); // "ex.varcode.TailoredMsg"
}
/*-}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment