001package beginner;
002
003import com.sandwich.koan.Koan;
004
005import static com.sandwich.koan.constant.KoanConstants.__;
006import static com.sandwich.util.Assert.assertEquals;
007
008public class AboutMethodPreference {
009
010    class A {
011        public String doStuff(int i) {
012            return "int";
013        }
014
015        public String doStuff(Integer i) {
016            return "Integer";
017        }
018
019        public String doStuff(Object i) {
020            return "Object";
021        }
022
023        public String doStuff(int... i) {
024            return "int vararg";
025        }
026    }
027
028    @Koan
029    public void methodPreferenceInt() {
030        assertEquals(new A().doStuff(1), __);
031    }
032
033    @Koan
034    public void methodPreferenceInteger() {
035        assertEquals(new A().doStuff(Integer.valueOf(1)), __);
036    }
037
038    @Koan
039    public void methodPreferenceLong() {
040        long l = 1;
041        assertEquals(new A().doStuff(l), __);
042    }
043
044    @Koan
045    public void methodPreferenceBoxedLong() {
046        Long l = Long.valueOf(1);
047        assertEquals(new A().doStuff(l), __);
048    }
049
050    @Koan
051    public void methodPreferenceDouble() {
052        Double l = Double.valueOf(1);
053        assertEquals(new A().doStuff(l), __);
054    }
055
056    @Koan
057    public void methodPreferenceMore() {
058        // What happens if you change 'Integer' to 'Double'
059        // Does this explain 'methodPreferenceDouble'?
060        // Think about why this happens?
061        assertEquals(new A().doStuff(1, Integer.valueOf(2)), __);
062    }
063}