摘要:
public class helloWorld2 { public static void main(String[] args) { System.out.println(new Soap()); }}class Soap { private String s; Soap() { s = new String("Constructed"); } public String toString() { return s; }}/* * output * Constructed */System.out是一个Pri... 阅读全文
摘要:
Java种有些类型并不是对象,如Int double boolean 等基本类型不是对象。而有的时候,我们希望它可以是对象的像是存在。如:你需要在Collection种放入一些整数,但是collection需要存入 的都是对象。而不是基本类型。这时你就得永封装对象。Java考虑到这方面的因素因此,为每种简单数据类型,都设计了封装类。基本的做法:Integer I= new Integer(100); 你可以永封装类的valueOf()方法,封装一个简单数据类型Integer i = Integer.valueOf(1);如果打算包裹的資料動作頻繁,而且是在某個小範圍之內,建議使用valueOf 阅读全文