Skip to content

Commit 67f3928

Browse files
committed
integrating new koans
1 parent c478307 commit 67f3928

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

koans/src/PathToEnlightment.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@
6666
<Koan name="complicatedCast" />
6767
<Koan name="complicatedCastWithInterface" />
6868
</Suite>
69+
<Suite class="AboutInheritance">
70+
<Koan name="differenceBetweenOverloadingAndOverriding" />
71+
<Koan name="overridenMethodsMayReturnSubtype"
72+
lesson="An overridden method may return a subtype of the return type for the method being overridden. Look at the javadoc for java.util.Collection or java.util.List - it will reveal how to eliminate this type cast."/>
73+
</Suite>
74+
<Suite class="AboutConstructors">
75+
<Koan name="simpleConstructorOrder" />
76+
<Koan name="complexConstructorOrder" />
77+
</Suite>
78+
<Suite class="AboutMethodPreference">
79+
<Koan name="methodPreferenceInt" />
80+
<Koan name="methodPreferenceInteger" />
81+
<Koan name="methodPreferenceLong" />
82+
<Koan name="methodPreferenceBoxedLong" />
83+
<Koan name="methodPreferenceDouble" />
84+
<Koan name="methodPreferenceMore" />
85+
</Suite>
86+
<Suite class="AboutOperators">
87+
<Koan name="plusPlusVariablePlusPlus" />
88+
<Koan name="shortCircuit" />
89+
<Koan name="fullAnd" />
90+
<Koan name="shortCircuitAnd" />
91+
<Koan name="aboutXOR" />
92+
<Koan name="dontMistakeEqualsForEqualsEquals" />
93+
</Suite>
6994
<Suite class="AboutArrays">
7095
<Koan name="arraysDoNotConsiderElementsWhenEvaluatingEquality"
7196
lesson="Arrays utilize reference equality, they do not consider elements when determining equality."/>

koans/src/beginner/AboutInheritance.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package beginner;
22

3-
import java.util.ArrayList;
3+
import static com.sandwich.koan.constant.KoanConstants.__;
4+
import static com.sandwich.util.Assert.assertEquals;
5+
46
import java.util.Collection;
7+
import java.util.Collections;
8+
import java.util.List;
59

610
import com.sandwich.koan.Koan;
7-
import static com.sandwich.koan.constant.KoanConstants.__;
8-
import static com.sandwich.util.Assert.assertEquals;
911

1012
public class AboutInheritance {
1113

@@ -25,18 +27,18 @@ public void differenceBetweenOverloadingAndOverriding() {
2527
}
2628

2729
abstract class ParentTwo {
28-
abstract public Collection doStuff();
30+
abstract public Collection<?> doStuff();
2931
}
3032

3133
class ChildTwo extends ParentTwo {
32-
public Collection doStuff() { return null; };
34+
public Collection<?> doStuff() { return Collections.emptyList(); };
3335
}
3436

3537
@Koan
3638
public void overridenMethodsMayReturnSubtype() {
3739
// What do you need to change in order to get rid of the type cast?
3840
// Why does this work?
39-
ArrayList arraylist = (ArrayList)new ChildTwo().doStuff();
40-
assertEquals(arraylist instanceof ArrayList, true);
41+
List<?> list = (List<?>)new ChildTwo().doStuff();
42+
assertEquals(list instanceof List, __);
4143
}
4244
}

0 commit comments

Comments
 (0)