private static BookManager instance = new BookManager(); 这么写有什么好处?不让你自行创建BookManager的实例toArray(Object[] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.不写参数当然要出错啊
这么写有什么好处?不让你自行创建BookManager的实例toArray(Object[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.不写参数当然要出错啊
单一实例的类的设计方法!!你没看到 构造函数是 private ,这样你在外面就不能new 他了啦!!!至于为什么是static 是为了让他在内存中只存在为一份 实例!!!return (Book[])books.values().toArray(new Book[0]);
那是toArray()是返回的一个object[]对象, 但是你却想转成Book[]对象
所以你要把参数给进去!!! 楼上的那段jdk 就是解释了这个问题!