Last active
June 22, 2022 21:23
-
-
Save xzer/5b6e79753a028ac4bbf371fcca5929f5 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
@Trait(impl=Counter.class) | |
interface CounterTrait { | |
public int countup(); | |
} | |
class Counter implements CounterTrait { | |
private int value = 0; | |
public int countup(){ | |
value++; | |
return value; | |
} | |
protected int countdown(){ | |
value--; | |
return value; | |
} | |
} | |
@UseTrait | |
class Foo implements CounterTrait { | |
public int countup(); | |
} | |
----------- | |
class Foo implements CounterTrait { | |
private static class CounterTraitDelegatee extends Counter { | |
protected int countdown(){ | |
super.countdown(); | |
} | |
} | |
private CounterTraitDelegatee __counter_trait_delegatee__ = new CounterTraitDelegatee() {}; | |
public int countup(){ | |
return __counter_trait_delegatee__.countup(); | |
} | |
protected int countdown(){ | |
return __counter_trait_delegatee__.countdown(); | |
} | |
} |
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
@Trait | |
abstract class Counter { | |
private int value = 0; | |
public int countup(){ | |
value++; | |
return value; | |
} | |
protected int countdown(){ | |
value--; | |
return value; | |
} | |
} | |
@UseTrait | |
class Foo implements CounterTrait { | |
} | |
----------- | |
@GeneratedTrait(base=Counter.class) | |
interface CounterTrait { | |
public int countup(); | |
} | |
class Foo implements CounterTrait { | |
private static class CounterTraitDelegatee extends Counter { | |
protected int countdown(){ | |
super.countdown(); | |
} | |
} | |
private CounterTraitDelegatee __counter_trait_delegatee__ = new CounterTraitDelegatee() {}; | |
public int countup(){ | |
return __counter_trait_delegatee__.countup(); | |
} | |
protected int countdown(){ | |
return __counter_trait_delegatee__.countdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment