Java百问
来源:互联网 发布:mac怎么查看群相册 编辑:程序博客网 时间:2024/05/16 15:42
http://www.programcreek.com/2013/04/java%E7%99%BE%E9%97%AE/
5.关于double的一个常见问题
6. String 不变性。
7 HashMap中 一定复写
public int hashCode() //产生一个散列值 ,为了存取方便,相当于地址
public boolean equals(Object obj)
1. If two objects are equal, then they must have the same hash code.
2. If two objects have the same hashcode, they may or may not be equal.
import java.util.HashMap;public class Apple { private String color; public Apple(String color) { this.color = color; } public int hashCode(){ System.out.println("判断hashcode"); return this.color.length(); } public boolean equals(Object obj) { System.out.println("判断equals"); if (!(obj instanceof Apple)) return false; if (obj == this) return true; return this.color == ((Apple) obj).color; } public static void main(String[] args) { Apple a1 = new Apple("green"); Apple a2 = new Apple("red"); Apple a3 = new Apple("green"); //hashMap stores apple type and its quantity HashMap<Apple, Integer> m = new HashMap<Apple, Integer>(); m.put(a1, 10);//判断hashcode m.put(a2, 20);//判断hashcode m.put(a3, 30);//判断hashcode 判断equals System.out.println(m.get(new Apple("green"))); //判断hashcode //判断equals //30 System.out.println(m.size()); //2 }}
13 Overriding and overloading
在同一个类中,出现多个同名的方法的现象就是Overload
覆写掉继承来的东西是Overriding。 用于多态。14 Fields不能被Overridden
19 私有构造函数:避免外部创建对象,用于单例。
39.Java是值传递还是址传递?为什么这样设计
值传递。object对象本身就是reference.
0 0
- Java百问
- Java百问
- Java百问
- Java百问
- java百问大全
- Java百问
- Java百问
- Java百问
- java百问
- java百问
- java百问总结(一)
- java百问总结(二)
- java百问总结(三)
- java百问总结(四)
- 百问
- java常见问题1000问
- java面试30问
- java面试30问
- jquery 对单选按钮遍历选择
- UIKeyboard键盘相关知识点-IOS开发
- JAVA多线程与并发学习总结
- Android 如何增加FM的音量(line in)
- 通过awk在Linux下打乱文件内容的顺序
- Java百问
- 关闭窗口时WM_CLOSE,WM_DESTROY,WM_QUIT消息
- Tomcat7中web应用加载原理(三)Listener、Filter、Servlet的加载和调用
- 安东尼-罗宾先生
- 技术资料收集~服务器
- 微信开发 接入参数
- sundesheng125
- android中设置view控件的gravity
- netfilter位于内核的那一层