1.如果两个对象根据equals(Object)方法是相等的,那么调用这两个对象中任一个对象的hashCode方法必须产生同样的整数结果。
2.非静态成员类必然持有一个外围类的实例的引用。
3.如果Sub为Super的子类,那么Sub[]就是Super[]的子类,而列表不是
4.重载和多态
public class CollectionClassifier{
public static String classify(Set s){
return "Set";
}
public static String classify(List l){
return "List";
}
public static String classify(Collection c){
return "Unknow Collection";
}
public static void main( String[] args )
Collection[] tests = new Collection[]{
new HashSet(),
new ArrayList(),
new HashMap().values()
}
for(int i=0;i<tests.length;i++)
System.out.println(classify(test[i]));
}
}
5.覆盖方法
class Wine {
String name() {
return "wine";
}
}
class SparklinWine extends Wine {
@Override
String name() {
// TODO Auto-generated method stub
return "SparklinWine";
}
}
class Champagne extends SparklinWine {
@Override
String name() {
// TODO Auto-generated method stub
return "Champagne";
}
}
public class Planet {
public static void main(String[] args) {
Wine[] wines={ new Wine(),new SparklinWine(),new Champagne()};
for (Wine wine : wines) {
System.out.println(wine.name());
}
}
}
6. new Integer(43)!=new Integer(43)
7.反射类成员
private ContentValues packagetPatientContentValues(JavaBean patient) {
ContentValues value = new ContentValues();
Field[] fields = patient.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (field.getModifiers() == Modifier.PRIVATE) {
String valStr = null;
try {
valStr = (String) field.get(patient);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
value.put(field.getName(), valStr);
}
}
return value;
}
2.非静态成员类必然持有一个外围类的实例的引用。
3.如果Sub为Super的子类,那么Sub[]就是Super[]的子类,而列表不是
4.重载和多态
public class CollectionClassifier{
public static String classify(Set s){
return "Set";
}
public static String classify(List l){
return "List";
}
public static String classify(Collection c){
return "Unknow Collection";
}
public static void main( String[] args )
Collection[] tests = new Collection[]{
new HashSet(),
new ArrayList(),
new HashMap().values()
}
for(int i=0;i<tests.length;i++)
System.out.println(classify(test[i]));
}
}
5.覆盖方法
class Wine {
String name() {
return "wine";
}
}
class SparklinWine extends Wine {
@Override
String name() {
// TODO Auto-generated method stub
return "SparklinWine";
}
}
class Champagne extends SparklinWine {
@Override
String name() {
// TODO Auto-generated method stub
return "Champagne";
}
}
public class Planet {
public static void main(String[] args) {
Wine[] wines={ new Wine(),new SparklinWine(),new Champagne()};
for (Wine wine : wines) {
System.out.println(wine.name());
}
}
}
6. new Integer(43)!=new Integer(43)
7.反射类成员
private ContentValues packagetPatientContentValues(JavaBean patient) {
ContentValues value = new ContentValues();
Field[] fields = patient.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (field.getModifiers() == Modifier.PRIVATE) {
String valStr = null;
try {
valStr = (String) field.get(patient);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
value.put(field.getName(), valStr);
}
}
return value;
}