Below is the presentation I used for my talk on Anti-If Campaign for Cincy Clean Coders today.
The source code used in the presentation is available in github.
The source code used in the presentation is available in github.
abstract class A{
def isWhat():Boolean
}
trait B extends A{
override def isWhat():Boolean = true;
}
trait C extends A{
override def isWhat():Boolean = false;
}
val a = new A with C with B;
println(a.isWhat());
public class AList<E> {
private final List<E> list;
public AList(List<E> list) {
super();
this.list = list;
}
public boolean add(E value){
return this.list.add(value);
}
public int size(){
return this.list.size();
}
public E[] toArray(E[] a) {
System.arraycopy(list.toArray(), 0, a, 0, size());
return a;
}
}
@Test
public void testAListToArray() {
AList list = new AList(new ArrayList());
list.add("Not type safe");
String[] sl = (String[]) list.toArray(new String[list.size()]);
assertEquals(sl.length, list.size());
AList<String> list2 = new AList<String>(new ArrayList<String>());
list2.add("Type safe");
String[] s2 = list2.toArray(new String[list.size()]);
assertEquals(s2.length, list2.size());
}