Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.

Commit 9657199

Browse files
author
Nicolai Parlog
committed
Rename mixins to traits
1 parent c999b10 commit 9657199

File tree

1 file changed

+29
-4
lines changed
  • src/main/java/org/codefx/demo/java10/lang/var

1 file changed

+29
-4
lines changed

src/main/java/org/codefx/demo/java10/lang/var/Mixins.java renamed to src/main/java/org/codefx/demo/java10/lang/var/Traits.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import java.math.BigDecimal;
44
import java.util.function.Supplier;
55

6-
public class Mixins {
6+
public class Traits {
7+
8+
public static void main(String[] args) {
9+
var ecorp = new ECorp();
10+
report(ecorp);
11+
}
712

813
/*
914
* DOWNSIDES
@@ -21,7 +26,7 @@ public class Mixins {
2126
* - utility methods
2227
*/
2328

24-
public void report(Megacorp megacorp) {
29+
public static void report(Megacorp megacorp) {
2530
// without `var` there would be no way to declare a variable
2631
// of type `IsSuccessful` and `IsEvil`
2732
var corp = (MegacorpDelegate & IsSuccessful & IsEvil) () -> megacorp;
@@ -46,6 +51,26 @@ interface Megacorp {
4651

4752
}
4853

54+
static class ECorp implements Megacorp {
55+
56+
@Override
57+
public String name() {
58+
return "E-Corp";
59+
}
60+
61+
@Override
62+
public BigDecimal earnings() {
63+
// "One. Million. Dollars"
64+
return new BigDecimal("1000000");
65+
}
66+
67+
@Override
68+
public BigDecimal taxes() {
69+
return BigDecimal.ONE;
70+
}
71+
72+
}
73+
4974
// created right next to `Megacorp` to allow easy extension
5075
// throughout the system
5176
@FunctionalInterface
@@ -77,11 +102,11 @@ default BigDecimal taxes() {
77102
// these are concepts that are only useful in a very narrow part of the system
78103
// and so they are not added to the original interface to prevent polluting it
79104
// with too many methods;
80-
// these mixins must not have abstract methods
105+
// these traits must not have abstract methods
81106

82107
interface IsSuccessful extends Megacorp {
83108

84-
final BigDecimal SUCCESS_BOUNDARY = new BigDecimal("500000000");
109+
BigDecimal SUCCESS_BOUNDARY = new BigDecimal("500000000");
85110

86111
default boolean isSuccessful() {
87112
return earnings().compareTo(SUCCESS_BOUNDARY) > 0;

0 commit comments

Comments
 (0)