import java.util.*; class A { protected T t; protected List list = new ArrayList(); } public class B extends A { void foo() { if (t == null) return; if (list == null) return; System.out.println(t); for (Object s : list) { //do nothing } } }